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

55 {
56 utils::Config::addStringOption("--web-root", "Root directory of the web site", "[path]");
57
58 express::WebApp::init(argc, argv);
59
60 using LegacyWebApp = express::legacy::in::WebApp;
61 using LegacySocketAddress = LegacyWebApp::SocketAddress;
62
63 const LegacyWebApp legacyApp;
64 legacyApp.getConfig().setReuseAddress();
65
67
68 legacyApp.listen(8080,
69 [instanceName = legacyApp.getConfig().getInstanceName()](const LegacySocketAddress& socketAddress,
70 const core::socket::State& state) {
71 switch (state) {
72 case core::socket::State::OK:
73 VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'";
74 break;
75 case core::socket::State::DISABLED:
76 VLOG(1) << instanceName << " disabled";
77 break;
78 case core::socket::State::ERROR:
79 LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what();
80 break;
81 case core::socket::State::FATAL:
82 LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what();
83 break;
84 }
85 });
86
87 using TLSWebApp = express::tls::in::WebApp;
88 using TLSSocketAddress = TLSWebApp::SocketAddress;
89
90 const TLSWebApp tlsApp;
91 tlsApp.getConfig().setReuseAddress();
92
93 tlsApp.getConfig().setCert("/home/voc/projects/snodec/snode.c/certs/wildcard.home.vchrist.at_-_snode.c_-_server.pem");
94 tlsApp.getConfig().setCertKey("/home/voc/projects/snodec/snode.c/certs/Volker_Christian_-_Web_-_snode.c_-_server.key.encrypted.pem");
95 tlsApp.getConfig().setCertKeyPassword("snode.c");
96
98
99 tlsApp.listen(
100 8088,
101 [instanceName = legacyApp.getConfig().getInstanceName()](const TLSSocketAddress& socketAddress, const core::socket::State& state) {
102 switch (state) {
103 case core::socket::State::OK:
104 VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'";
105 break;
106 case core::socket::State::DISABLED:
107 VLOG(1) << instanceName << " disabled";
108 break;
109 case core::socket::State::ERROR:
110 LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what();
111 break;
112 case core::socket::State::FATAL:
113 LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what();
114 break;
115 }
116 });
117
118 return express::WebApp::start();
119}
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
static CLI::Option * addStringOption(const std::string &name, const std::string &description, const std::string &typeName)
Definition Config.cpp:885
static std::string getStringOptionValue(const std::string &name)
Definition Config.cpp:942
WebAppT< web::http::legacy::in::Server > WebApp
Definition WebApp.h:54
WebAppT< web::http::tls::in::Server > WebApp
Definition WebApp.h:54

References core::socket::State::DISABLED, core::socket::State::ERROR, core::socket::State::FATAL, core::socket::Socket< ConfigT >::getConfig(), net::config::ConfigInstance::getInstanceName(), express::WebApp::init(), net::in::stream::SocketServer< SocketAcceptorT, ConfigSocketServerT, SocketContextFactoryT, Args >::listen(), core::socket::State::OK, net::config::ConfigTls::setCert(), net::config::ConfigTls::setCertKey(), net::config::ConfigTls::setCertKeyPassword(), net::in::stream::config::ConfigSocketServer::setReuseAddress(), express::WebApp::start(), net::in::SocketAddress::toString(), and core::socket::State::what().

Here is the call graph for this function: