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 52 of file testpost.cpp.

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

References express::Request::body, core::socket::State::DISABLED, core::socket::State::ERROR, core::socket::State::FATAL, core::socket::Socket< ConfigT >::getConfig(), express::WebApp::init(), net::in::stream::SocketServer< SocketAcceptorT, ConfigSocketServerT, SocketContextFactoryT, Args >::listen(), net::in::stream::SocketServer< SocketAcceptorT, ConfigSocketServerT, SocketContextFactoryT, Args >::listen(), core::socket::State::OK, express::Response::send(), net::config::ConfigTls::setCert(), net::config::ConfigTls::setCertKey(), net::config::ConfigTls::setCertKeyPassword(), net::in::stream::config::ConfigSocketServer::setReuseAddress(), express::WebApp::start(), net::in::SocketAddress::toString(), and express::WebAppT< ServerT >::WebAppT().

Here is the call graph for this function: