52 {
54
56 using LegacySocketAddress = LegacyWebApp::SocketAddress;
57
58 const LegacyWebApp legacyApp("legacy");
59 legacyApp.getConfig().setReuseAddress();
60
62
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
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
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
155}
#define APPLICATION(req, res)
static constexpr int DISABLED
static constexpr int ERROR
static constexpr int FATAL
static void init(int argc, char *argv[])
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
WebAppT< web::http::legacy::in::Server > WebApp
WebAppT< web::http::tls::in::Server > WebApp