#include <uwebsockets/App.h>
#include <chrono>
#include <functional>
#include <nlohmann/json.hpp>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include "api/router.h"
Go to the source code of this file.
|
| namespace | mm |
| |
| namespace | mm::node |
| |
| namespace | mm::api |
| | HTTP-transport glue shared by the built-in server and route plug-in libs.
|
| |
|
| template<typename Res > |
| Res * | mm::api::setCorsOrigin (Res *res, std::string_view corsOrigin) |
| | Writes the Access-Control-Allow-Origin header and returns res for chaining.
|
| |
| template<typename Res > |
| Res * | mm::api::setWireTime (Res *res, std::chrono::microseconds wireUs) |
| | Attaches the server-measured wire-time header (X-Wire-Us, microseconds) to a response.
|
| |
| template<typename Res > |
| 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.
|
| |
| template<typename Res > |
| void | mm::api::sendBytes (Res *res, std::string_view corsOrigin, std::string_view contentType, std::string_view body) |
| | Writes body verbatim as a 200 response with the given contentType and the CORS header.
|
| |
| template<typename Res > |
| void | mm::api::sendError (Res *res, std::string_view status, std::string_view corsOrigin, std::string_view message, std::optional< std::chrono::microseconds > wireUs=std::nullopt) |
| | Writes a status response carrying a {"error": message} JSON body and the CORS header.
|
| |
| template<typename Res > |
| void | mm::api::sendStatus (Res *res, std::string_view status, std::string_view corsOrigin, std::optional< std::chrono::microseconds > wireUs=std::nullopt) |
| | Writes a bare status response (no body) with the CORS header.
|
| |