SNode.C
Loading...
Searching...
No Matches
testpost.cpp File Reference
Include dependency graph for testpost.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 32 of file testpost.cpp.

32 {
33 express::WebApp::init(argc, argv);
34
35 using LegacyWebApp = express::legacy::in::WebApp;
36 using LegacySocketAddress = LegacyWebApp::SocketAddress;
37
38 const LegacyWebApp legacyApp("legacy");
39 legacyApp.getConfig().setReuseAddress();
40
42
43 legacyApp.get("/", [] APPLICATION(req, res) {
44 res->send("<html>"
45 " <head>"
46 " <style>"
47 " main {"
48 " min-height: 30em;"
49 " padding: 3em;"
50 " background-image: repeating-radial-gradient( circle at 0 0, #fff, #ddd 50px);"
51 " }"
52 " input[type=\"file\"] {"
53 " display: block;"
54 " margin: 2em;"
55 " padding: 2em;"
56 " border: 1px dotted;"
57 " }"
58 " </style>"
59 " </head>"
60 " <body>"
61 " <h1>File-Upload with input type=\"file\"</h1>"
62 " <main>"
63 " <h2>Send us something fancy!</h2>"
64 " <form method=\"post\" enctype=\"multipart/form-data\">"
65 " <label> Select a text file (*.txt, *.html etc.) from your computer."
66 " <input name=\"datei\" type=\"file\" size=\"50\" accept=\"text/*\">"
67 " </label>"
68 " <button>… and off we go!</button>"
69 " </form>"
70 " </main>"
71 " </body>"
72 "</html>");
73 });
74
75 legacyApp.post("/", [] APPLICATION(req, res) {
76 res->send("<html>\n"
77 " <body>\n"
78 " <h1>Thank you, we received your file!</h1>\n"
79 " <h2>Content:</h2>\n"
80 " <pre>\n" +
81 std::string(req->body.begin(), req->body.end()) +
82 " </pre>\n"
83 " </body>\n"
84 "</html>\n");
85 });
86
87 legacyApp.listen(8080, [](const LegacySocketAddress& socketAddress, const core::socket::State& state) {
88 switch (state) {
90 VLOG(1) << "legacyApp: listening on '" << socketAddress.toString() << "'";
91 break;
93 VLOG(1) << "legacyApp: disabled";
94 break;
96 VLOG(1) << "legacyApp: error occurred";
97 break;
99 VLOG(1) << "legacyApp: fatal error occurred";
100 break;
101 }
102 });
103
104 using TLSWebApp = express::tls::in::WebApp;
105 using TLSSocketAddress = TLSWebApp::SocketAddress;
106
107 const TLSWebApp tlsApp("tls");
108 tlsApp.getConfig().setReuseAddress();
109
110 tlsApp.getConfig()
111 .setCert("/home/voc/projects/snodec/snode.c/certs/wildcard.home.vchrist.at_-_snode.c_-_server.pem")
112 .setCertKey("/home/voc/projects/snodec/snode.c/certs/Volker_Christian_-_Web_-_snode.c_-_server.key.encrypted.pem")
113 .setCertKeyPassword("snode.c");
114
115 tlsApp.use(legacyApp);
116
117 tlsApp.listen("localhost", 8088, [](const TLSSocketAddress& socketAddress, const core::socket::State& state) {
118 switch (state) {
120 VLOG(1) << "tlsApp: listening on '" << socketAddress.toString() << "'";
121 break;
123 VLOG(1) << "tlsApp: disabled";
124 break;
126 VLOG(1) << "tlsApp: error occurred";
127 break;
129 VLOG(1) << "tlsApp: fatal error occurred";
130 break;
131 }
132 });
133
134 return express::WebApp::start();
135}
#define APPLICATION(req, res)
Definition Router.h:45
static constexpr int DISABLED
Definition State.h:34
static constexpr int ERROR
Definition State.h:35
static constexpr int FATAL
Definition State.h:36
static constexpr int OK
Definition State.h:33
static void init(int argc, char *argv[])
Definition WebApp.cpp:34
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Definition WebApp.cpp:38
WebAppT< web::http::legacy::in::ServerBase< web::http::server::Request, web::http::server::Response > > WebApp
Definition WebApp.h:32
WebAppT< web::http::tls::in::ServerBase< web::http::server::Request, web::http::server::Response > > WebApp
Definition WebApp.h:32

References express::WebApp::init(), and express::WebApp::start().

Here is the call graph for this function: