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 64 of file httpserver.cpp.

64 {
65 using WebApp = apps::http::STREAM::WebApp;
66
67 const WebApp webApp(apps::http::STREAM::getWebApp("httpserver"));
68
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);
72
73 WebApp::init(argc, argv);
74
75 webApp.get(express::middleware::StaticMiddleware(htmlRoot->as<std::string>()));
76
77 {
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";
82
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}}}};
86
87 webApp.getConfig().addSniCerts(sniCerts);
88#endif
89
90 VLOG(1) << "Routes:";
91 for (std::string& route : webApp.getRoutes()) {
92 route.erase(std::remove(route.begin(), route.end(), '$'), route.end());
93
94 VLOG(1) << " " << route;
95 }
96
97 webApp.listen([instanceName = webApp.getConfig().getInstanceName()](const core::socket::SocketAddress& socketAddress,
98 const core::socket::State& state) {
99 switch (state) {
100 case core::socket::State::OK:
101 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
102 break;
103 case core::socket::State::DISABLED:
104 VLOG(1) << instanceName << ": disabled";
105 break;
106 case core::socket::State::ERROR:
107 VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
108 break;
109 case core::socket::State::FATAL:
110 VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
111 break;
112 }
113 });
114 }
115 return WebApp::start();
116}
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
CLI::Option * addOption(const std::string &name, const std::string &description)
void required(CLI::Option *opt, bool req=true)