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/VerboseRequest.h"
44#include "express/tls/in/WebApp.h"
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
48#include "log/Logger.h"
54int main(
int argc,
char* argv[]) {
57 using LegacyWebApp = express::legacy::in::WebApp;
58 using LegacySocketAddress = LegacyWebApp::SocketAddress;
60 const LegacyWebApp legacyApp
("legacy");
63 legacyApp.use(express::middleware::VerboseRequest());
72 " background-image: repeating-radial-gradient( circle at 0 0, #fff, #ddd 50px);"
74 " input[type=\"file\"] {"
78 " border: 1px dotted;"
83 " <h1>File-Upload with input type=\"file\"</h1>"
85 " <h2>Send us something fancy!</h2>"
86 " <form method=\"post\" enctype=\"multipart/form-data\">"
87 " <label> Select a text file (*.txt, *.html etc.) from your computer."
88 " <input name=\"datei\" type=\"file\" size=\"50\" accept=\"text/*\">"
90 " <button>… and off we go!</button>"
100 " <h1>Thank you, we received your file!</h1>\n"
101 " <h2>Content:</h2>\n"
103 std::string(req->
body.begin(), req->
body.end()) +
109 legacyApp
.listen(8080
, [](
const LegacySocketAddress& socketAddress,
const core::socket::
State& state) {
112 VLOG(1) <<
"legacyApp: listening on '" << socketAddress
.toString() <<
"'";
115 VLOG(1) <<
"legacyApp: disabled";
118 VLOG(1) <<
"legacyApp: error occurred";
121 VLOG(1) <<
"legacyApp: fatal error occurred";
126 using TLSWebApp = express::tls::in::WebApp;
127 using TLSSocketAddress = TLSWebApp::SocketAddress;
129 const TLSWebApp tlsApp
("tls");
133 .setCert("/home/voc/projects/snodec/snode.c/certs/wildcard.home.vchrist.at_-_snode.c_-_server.pem")
134 .setCertKey("/home/voc/projects/snodec/snode.c/certs/Volker_Christian_-_Web_-_snode.c_-_server.key.encrypted.pem")
137 tlsApp.use(legacyApp);
139 tlsApp
.listen("localhost", 8088
, [](
const TLSSocketAddress& socketAddress,
const core::socket::
State& state) {
142 VLOG(1) <<
"tlsApp: listening on '" << socketAddress
.toString() <<
"'";
145 VLOG(1) <<
"tlsApp: disabled";
148 VLOG(1) <<
"tlsApp: error occurred";
151 VLOG(1) <<
"tlsApp: fatal error occurred";
#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})
ConfigTls & setCert(const std::string &cert)
ConfigTls & setCertKey(const std::string &certKey)
ConfigTls & setCertKeyPassword(const std::string &certKeyPassword)
std::string toString(bool expanded=true) const override
void listen(const std::string &ipOrHostname, uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
ConfigSocketServer & setReuseAddress(bool reuseAddress=true)
int main(int argc, char *argv[])