|
Motion Master 6.0.0-alpha.50
Next-generation motion control software
|
HTTP-transport glue shared by the built-in server and route plug-in libs. More...
Classes | |
| struct | RouteContext |
| The live collaborators a route plug-in needs, handed to it at registration time. More... | |
Typedefs | |
| using | RegisterRoutesFn = std::function< void(uWS::SSLApp &app, const RouteContext &ctx)> |
| A route plug-in: registers its routes on the HTTP app. | |
Functions | |
| template<typename Res > | |
| void | sendJson (Res *res, std::string_view corsOrigin, const nlohmann::json &body) |
Writes body as a 200 application/json response with the CORS header. | |
| template<typename Res > | |
| void | sendError (Res *res, std::string_view status, std::string_view corsOrigin, std::string_view message) |
Writes a status response carrying a {"error": message} JSON body and the CORS header. | |
| template<typename Res > | |
| void | sendStatus (Res *res, std::string_view status, std::string_view corsOrigin) |
Writes a bare status response (no body) with the CORS header. | |
HTTP-transport glue shared by the built-in server and route plug-in libs.
This layer sits above mm::node (the transport-agnostic domain layer) and below the app: it is the one place that knows about uWebSockets. mm::node must never depend on it. It exists so a route plug-in lib (e.g. mm::example) can register endpoints with the exact same response shape (content type + CORS) as the built-in routes without depending on the app.
| using mm::api::RegisterRoutesFn = typedef std::function<void(uWS::SSLApp& app, const RouteContext& ctx)> |
A route plug-in: registers its routes on the HTTP app.
Called once, on the HTTP server's event-loop thread, after the built-in routes and before the CORS preflight, the catch-all 404, and listen(). A plug-in should register only its own specific paths (e.g. /api/example/...); the server owns the OPTIONS /api/* preflight and the /* fallthrough. Registration order does not affect matching — uWS routes by specificity — but a plug-in must not claim /api/* or /* wildcards.
Wire one up in the composition root with HttpServer::addRoutes (before start()).
| void mm::api::sendError | ( | Res * | res, |
| std::string_view | status, | ||
| std::string_view | corsOrigin, | ||
| std::string_view | message | ||
| ) |
Writes a status response carrying a {"error": message} JSON body and the CORS header.
| void mm::api::sendJson | ( | Res * | res, |
| std::string_view | corsOrigin, | ||
| const nlohmann::json & | body | ||
| ) |
Writes body as a 200 application/json response with the CORS header.
Uses the replace error handler so a string-typed value carrying non-UTF-8 bytes (e.g. a garbage VISIBLE_STRING from a misbehaving device) is rendered with U+FFFD instead of throwing — an uncaught throw on the uWS loop terminates the whole server.
| void mm::api::sendStatus | ( | Res * | res, |
| std::string_view | status, | ||
| std::string_view | corsOrigin | ||
| ) |
Writes a bare status response (no body) with the CORS header.