2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "express/legacy/in/WebApp.h"
43#include "express/middleware/JsonMiddleware.h"
45#ifndef DOXYGEN_SHOULD_SKIP_THIS
47#include "log/Logger.h"
49#include <nlohmann/json.hpp>
56int main(
int argc,
char* argv[]) {
57 using WebApp = express::legacy::in::WebApp;
61 using SocketAddress = WebApp::SocketAddress;
63 const WebApp legacyApp
("legacy-jsonserver");
65 legacyApp.use(express::middleware::JsonMiddleware());
72 VLOG(1) << instanceName <<
": listening on '" << socketAddress
.toString() <<
"'";
75 VLOG(1) << instanceName <<
": disabled";
78 LOG(ERROR) << instanceName <<
": " << socketAddress
.toString() <<
": " << state
.what();
81 LOG(FATAL) << instanceName <<
": " << socketAddress
.toString() <<
": " << state
.what();
86 legacyApp.post(
"/index.html", []
APPLICATION(req, res) {
87 std::string jsonString;
90 [&jsonString](nlohmann::json& json) {
91 jsonString = json.dump(4);
92 VLOG(1) <<
"Application received body: " << jsonString;
94 [](
const std::string& key) {
95 VLOG(1) << key <<
" attribute not found";
#define APPLICATION(req, res)
Config & getConfig() const
static constexpr int DISABLED
static constexpr int ERROR
static constexpr int FATAL
void send(const std::string &chunk)
WebAppT(const std::string &name)
static void init(int argc, char *argv[])
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
const std::string & getInstanceName() const
std::string toString(bool expanded=true) const override
void listen(uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void getAttribute(const std::function< void(Attribute &)> &onFound, const std::function< void(const std::string &)> &onNotFound, const std::string &subKey="") const
int main(int argc, char *argv[])