36 {
38
39 WebApp::init(argc, argv);
40
41
42
44
45 WebApp legacyApp(
"legacy-jsonserver");
46
48
49 legacyApp.listen(
50 8080,
51 [instanceName = legacyApp.getConfig().getInstanceName()](
const SocketAddress& socketAddress,
const core::socket::State& state) {
52 switch (state) {
53 case core::socket::State::OK:
54 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
55 break;
56 case core::socket::State::DISABLED:
57 VLOG(1) << instanceName << ": disabled";
58 break;
59 case core::socket::State::ERROR:
60 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
61 break;
62 case core::socket::State::FATAL:
63 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
64 break;
65 }
66 });
67
68 legacyApp.post(
"/index.html", []
APPLICATION(req, res) {
69 std::string jsonString;
70
71 req->getAttribute<nlohmann::json>(
72 [&jsonString](nlohmann::json& json) {
73 jsonString = json.dump(4);
74 VLOG(1) << "Application received body: " << jsonString;
75 },
76 [](const std::string& key) {
77 VLOG(1) << key << " attribute not found";
78 });
79
80 res->send(jsonString);
81 });
82
84 res->send("Wrong Url");
85 });
86
87 return WebApp::start();
88}
#define APPLICATION(req, res)
express::legacy::NET::WebApp WebApp
WebAppT< web::http::legacy::in::ServerBase< web::http::server::Request, web::http::server::Response > > WebApp
SocketClient::SocketAddress SocketAddress