3#include <uwebsockets/App.h>
6#include <nlohmann/json.hpp>
12class MonitoringManager;
64template <
typename Res>
65void sendJson(Res* res, std::string_view corsOrigin,
const nlohmann::json& body) {
66 res->writeHeader(
"Content-Type",
"application/json")
67 ->writeHeader(
"Access-Control-Allow-Origin", corsOrigin)
68 ->end(body.dump(-1,
' ',
false, nlohmann::json::error_handler_t::replace));
73template <
typename Res>
74void sendError(Res* res, std::string_view status, std::string_view corsOrigin,
75 std::string_view message) {
76 res->writeStatus(status)
77 ->writeHeader(
"Content-Type",
"application/json")
78 ->writeHeader(
"Access-Control-Allow-Origin", corsOrigin)
79 ->end(nlohmann::json{{
"error", std::string(message)}}.dump());
83template <
typename Res>
84void sendStatus(Res* res, std::string_view status, std::string_view corsOrigin) {
85 res->writeStatus(status)->writeHeader(
"Access-Control-Allow-Origin", corsOrigin)->end();
Owns the fieldbus driver and node collection, and drives PDO exchange.
Definition device_manager.h:181
Owns the active monitorings and turns each into a lossless stream of recorded rows.
Definition monitoring_manager.h:46
HTTP-transport glue shared by the built-in server and route plug-in libs.
Definition web_api.h:21
void sendStatus(Res *res, std::string_view status, std::string_view corsOrigin)
Writes a bare status response (no body) with the CORS header.
Definition web_api.h:84
std::function< void(uWS::SSLApp &app, const RouteContext &ctx)> RegisterRoutesFn
A route plug-in: registers its routes on the HTTP app.
Definition web_api.h:57
void sendJson(Res *res, std::string_view corsOrigin, const nlohmann::json &body)
Writes body as a 200 application/json response with the CORS header.
Definition web_api.h:65
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.
Definition web_api.h:74
Definition http_server.h:16
The live collaborators a route plug-in needs, handed to it at registration time.
Definition web_api.h:39
mm::node::MonitoringManager & monitoringManager
Monitoring registry (for monitoring-aware plug-ins).
Definition web_api.h:43
std::string_view corsOrigin
Value to send in Access-Control-Allow-Origin; outlives run().
Definition web_api.h:45
mm::node::DeviceManager & deviceManager
Device list + SDO/PDO/state/bus access.
Definition web_api.h:41