SNode.C
Loading...
Searching...
No Matches
jsonserver.cpp File Reference
Include dependency graph for jsonserver.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 56 of file jsonserver.cpp.

56 {
58
59 WebApp::init(argc, argv);
60
61 using SocketAddress = WebApp::SocketAddress;
62
63 const WebApp legacyApp("legacy-jsonserver");
64
66
67 legacyApp.listen(
68 8080,
69 [instanceName = legacyApp.getConfig().getInstanceName()](const SocketAddress& socketAddress, const core::socket::State& state) {
70 switch (state) {
71 case core::socket::State::OK:
72 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
73 break;
74 case core::socket::State::DISABLED:
75 VLOG(1) << instanceName << ": disabled";
76 break;
77 case core::socket::State::ERROR:
78 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
79 break;
80 case core::socket::State::FATAL:
81 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
82 break;
83 }
84 });
85
86 legacyApp.post("/index.html", [] APPLICATION(req, res) {
87 std::string jsonString;
88
89 req->getAttribute<nlohmann::json>(
90 [&jsonString](nlohmann::json& json) {
91 jsonString = json.dump(4);
92 VLOG(1) << "Application received body: " << jsonString;
93 },
94 [](const std::string& key) {
95 VLOG(1) << key << " attribute not found";
96 });
97
98 res->send(jsonString);
99 });
100
101 legacyApp.post([] APPLICATION(req, res) {
102 res->send("Wrong Url");
103 });
104
105 return WebApp::start();
106}
#define APPLICATION(req, res)
Definition Router.h:68
express::legacy::NET::WebApp WebApp
Definition servers.h:76
WebAppT< web::http::legacy::in::Server > WebApp
Definition WebApp.h:54
SocketClient::SocketAddress SocketAddress

References core::socket::State::DISABLED, core::socket::State::ERROR, core::socket::State::FATAL, utils::MultibleAttributeInjector::getAttribute(), core::socket::Socket< ConfigT >::getConfig(), net::config::ConfigInstance::getInstanceName(), express::WebApp::init(), net::in::stream::SocketServer< SocketAcceptorT, ConfigSocketServerT, SocketContextFactoryT, Args >::listen(), core::socket::State::OK, express::Response::send(), express::WebApp::start(), net::in::SocketAddress::toString(), express::WebAppT< ServerT >::WebAppT(), and core::socket::State::what().

Here is the call graph for this function: