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 "apps/http/model/servers.h"
43#include "express/middleware/StaticMiddleware.h"
44#include "net/config/ConfigSection.hpp"
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
48#if (STREAM_TYPE == TLS)
55#include "log/Logger.h"
62using namespace express;
64int main(
int argc,
char* argv[]) {
65 using WebApp = apps::http::STREAM::WebApp;
67 const WebApp webApp(apps::http::STREAM::getWebApp(
"httpserver"));
69 net::
config::ConfigSection configWeb = net::
config::ConfigSection(&webApp.getConfig(),
"www",
"Web behavior of httpserver");
70 CLI::Option* htmlRoot = configWeb.addOption(
"--html-root",
"HTML root directory",
"path",
"");
71 configWeb.required(htmlRoot);
73 WebApp::init(argc, argv);
75 webApp.get(express::middleware::StaticMiddleware(htmlRoot->as<std::string>()));
78#if (STREAM_TYPE == TLS)
79 std::string cert =
"/home/voc/projects/snodec/snode.c/certs/snode.c_-_server.pem";
80 std::string key =
"/home/voc/projects/snodec/snode.c/certs/Volker_Christian_-_Web_-_snode.c_-_server.key.encrypted.pem";
81 std::string pass =
"snode.c";
83 std::map<std::string, std::map<std::string, std::variant<std::string,
bool, ssl_option_t>>> sniCerts = {
84 {
"snodec.home.vchrist.at", {{
"Cert", cert}, {
"CertKey", key}, {
"CertKeyPassword", pass}}},
85 {
"www.vchrist.at", {{
"Cert", cert}, {
"CertKey", key}, {
"CertKeyPassword", pass}}}};
87 webApp.getConfig().addSniCerts(sniCerts);
91 for (std::string& route : webApp.getRoutes()) {
92 route.erase(std::remove(route.begin(), route.end(),
'$'), route.end());
94 VLOG(1) <<
" " << route;
97 webApp.listen([instanceName = webApp.getConfig().getInstanceName()](
const core::socket::SocketAddress& socketAddress,
98 const core::socket::State& state) {
100 case core::socket::State::OK:
101 VLOG(1) << instanceName <<
": listening on '" << socketAddress.toString() <<
"'";
103 case core::socket::State::DISABLED:
104 VLOG(1) << instanceName <<
": disabled";
106 case core::socket::State::ERROR:
107 VLOG(1) << instanceName <<
": " << socketAddress.toString() <<
": " << state.what();
109 case core::socket::State::FATAL:
110 VLOG(1) << instanceName <<
": " << socketAddress.toString() <<
": " << state.what();
115 return WebApp::start();
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
int main(int argc, char *argv[])