mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-26 05:50:14 +00:00
http: add /ready
This commit is contained in:
2 files changed
+45
-2
No files matched your search
+26
-2
@@ -1,12 +1,36 @@
|
|||||||
openapi: "3.0.2"
|
openapi: "3.0.2"
|
||||||
info:
|
info:
|
||||||
title: API Title
|
title: BeamMP-Server
|
||||||
version: "1.0"
|
version: "1.0"
|
||||||
|
description: |
|
||||||
|
The BeamMP-Server optionally runs an HTTP server
|
||||||
|
which can be used to query information about the server's
|
||||||
|
status, health, players, etc.
|
||||||
servers:
|
servers:
|
||||||
- url: https://localhost:8000/v1
|
- url: http://localhost:{port}/v1
|
||||||
|
description: local BeamMP-Server
|
||||||
|
variables:
|
||||||
|
port:
|
||||||
|
default: "8000"
|
||||||
paths:
|
paths:
|
||||||
|
/ready:
|
||||||
|
get:
|
||||||
|
summary: whether the server has started fully
|
||||||
|
description: |
|
||||||
|
True once all subsystems have started up.
|
||||||
|
This doesn't tell you whether they're healthy,
|
||||||
|
check /health for that information.
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
"text/plain":
|
||||||
|
schema:
|
||||||
|
type: boolean
|
||||||
|
|
||||||
/health:
|
/health:
|
||||||
get:
|
get:
|
||||||
|
summary: health of the server's systems
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
|
|||||||
@@ -157,6 +157,25 @@ void Http::Server::THttpServerInstance::operator()() try {
|
|||||||
HttpLibServerInstance->Get("/", [](const httplib::Request&, httplib::Response& res) {
|
HttpLibServerInstance->Get("/", [](const httplib::Request&, httplib::Response& res) {
|
||||||
res.set_content("<!DOCTYPE html><article><h1>Hello World!</h1><section><p>BeamMP Server can now serve HTTP requests!</p></section></article></html>", "text/html");
|
res.set_content("<!DOCTYPE html><article><h1>Hello World!</h1><section><p>BeamMP Server can now serve HTTP requests!</p></section></article></html>", "text/html");
|
||||||
});
|
});
|
||||||
|
HttpLibServerInstance->Get(API_V1 "/ready", [](const httplib::Request&, httplib::Response& res) {
|
||||||
|
auto Statuses = Application::GetSubsystemStatuses();
|
||||||
|
bool Started = true;
|
||||||
|
for (const auto& NameStatusPair : Statuses) {
|
||||||
|
switch (NameStatusPair.second) {
|
||||||
|
case Application::Status::Starting:
|
||||||
|
case Application::Status::ShuttingDown:
|
||||||
|
case Application::Status::Shutdown:
|
||||||
|
Started = false;
|
||||||
|
break;
|
||||||
|
case Application::Status::Good:
|
||||||
|
case Application::Status::Bad:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.status = 200;
|
||||||
|
res.set_content(Started ? "true" : "false", "text/plain");
|
||||||
|
});
|
||||||
|
|
||||||
HttpLibServerInstance->Get(API_V1 "/health", [](const httplib::Request&, httplib::Response& res) {
|
HttpLibServerInstance->Get(API_V1 "/health", [](const httplib::Request&, httplib::Response& res) {
|
||||||
size_t SystemsGood = 0;
|
size_t SystemsGood = 0;
|
||||||
size_t SystemsBad = 0;
|
size_t SystemsBad = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user