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

39 {
40 using WebApp = apps::http::STREAM::WebApp;
41
42 const WebApp webApp(apps::http::STREAM::getWebApp("httpserver"));
43
44 net::config::ConfigSection configWeb = net::config::ConfigSection(&webApp.getConfig(), "www", "Web behavior of httpserver");
45 CLI::Option* htmlRoot = configWeb.addOption("--html-root", "HTML root directory", "path", "");
46 configWeb.required(htmlRoot);
47
48 WebApp::init(argc, argv);
49
50 webApp.use(express::middleware::StaticMiddleware(htmlRoot->as<std::string>()));
51
52 {
53#if (STREAM_TYPE == TLS)
54 std::string cert = "/home/voc/projects/snodec/snode.c/certs/snode.c_-_server.pem";
55 std::string key = "/home/voc/projects/snodec/snode.c/certs/Volker_Christian_-_Web_-_snode.c_-_server.key.encrypted.pem";
56 std::string pass = "snode.c";
57
58 std::map<std::string, std::map<std::string, std::variant<std::string, bool, ssl_option_t>>> sniCerts = {
59 {"snodec.home.vchrist.at", {{"Cert", cert}, {"CertKey", key}, {"CertKeyPassword", pass}}},
60 {"www.vchrist.at", {{"Cert", cert}, {"CertKey", key}, {"CertKeyPassword", pass}}}};
61
62 webApp.getConfig().addSniCerts(sniCerts);
63#endif
64
65 webApp.listen([instanceName = webApp.getConfig().getInstanceName()](const core::socket::SocketAddress& socketAddress,
66 const core::socket::State& state) {
67 switch (state) {
68 case core::socket::State::OK:
69 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
70 break;
71 case core::socket::State::DISABLED:
72 VLOG(1) << instanceName << ": disabled";
73 break;
74 case core::socket::State::ERROR:
75 VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
76 break;
77 case core::socket::State::FATAL:
78 VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
79 break;
80 }
81 });
82 }
83 return WebApp::start();
84}
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
CLI::Option * addOption(const std::string &name, const std::string &description)
void required(CLI::Option *opt, bool req=true)