SNode.C
Loading...
Searching...
No Matches
vhostserver.cpp File Reference
Include dependency graph for vhostserver.cpp:

Go to the source code of this file.

Functions

Router getRouter (const std::string &webRoot)
int main (int argc, char *argv[])

Function Documentation

◆ getRouter()

Router getRouter ( const std::string & webRoot)

Definition at line 57 of file vhostserver.cpp.

57 {
58 const Router router;
59
61
62 return router;
63}
Router router(database::mariadb::MariaDBClient &db)
Definition testregex.cpp:67

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 65 of file vhostserver.cpp.

65 {
67
68 WebApp::init(argc, argv);
69
70 {
71 const legacy::in6::WebApp legacyApp("legacy");
72
73 const Router& vh1 = middleware::VHost("localhost:8080");
74 vh1.use(middleware::StaticMiddleware(utils::Config::configRoot.getSubCommand<subcommand::ConfigWWW>()->getHtmlRoot()));
75 legacyApp.use(vh1);
76
77 const Router& vh2 = middleware::VHost("jupiter.home.vchrist.at");
78 vh2.get("/",
79 [] MIDDLEWARE(req, res, next) {
80 if (req->query("how").empty()) {
81 next();
82 } else if (req->query("how") == "route") {
83 next("route");
84 } else if (req->query("how") == "router") {
85 next("router");
86 }
87 })
88 .get([] APPLICATION(req, res) {
89 res->send("Hello! I am VHOST jupiter.home.vchrist.at.");
90 });
91 legacyApp.use(vh2);
92
93 const Router& vh3 = middleware::VHost("atlas.home.vchrist.at:8080");
94 vh3.get("/",
95 [] MIDDLEWARE(req, res, next) {
96 if (req->query("how").empty()) {
97 next();
98 } else if (req->query("how") == "route") {
99 next("route");
100 } else if (req->query("how") == "router") {
101 next("router");
102 }
103 })
104 .get([] APPLICATION(req, res) {
105 res->send("Hello! I am VHOST atlas.home.vchrist.at.");
106 });
107 vh3.get("/", [] APPLICATION(req, res) {
108 res->send("Hello, next route on atlas.home.vchrist.at");
109 });
110 vh3.get("/test", [] APPLICATION(req, res) {
111 res->send("Test Route on VHOST atlas.home.vchrist.at.");
112 });
113 legacyApp.use(vh3);
114
115 legacyApp.use([] APPLICATION(req, res) {
116 res->status(404).send("The requested resource is not found.");
117 });
118
119 legacyApp.listen(8080,
120 [instanceName = legacyApp.getConfig()->getInstanceName()](const legacy::in6::WebApp::SocketAddress& socketAddress,
121 const core::socket::State& state) {
122 switch (state) {
123 case core::socket::State::OK:
124 VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'";
125 break;
126 case core::socket::State::DISABLED:
127 VLOG(1) << instanceName << " disabled";
128 break;
129 case core::socket::State::ERROR:
130 LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what();
131 break;
132 case core::socket::State::FATAL:
133 LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what();
134 break;
135 }
136 });
137 }
138
139 {
140 const express::tls::in6::WebApp tlsApp("tls");
141
142 const Router& vh1 = middleware::VHost("localhost:8088");
143 vh1.use(middleware::StaticMiddleware(utils::Config::configRoot.getSubCommand<subcommand::ConfigWWW>()->getHtmlRoot()));
144 tlsApp.use(vh1);
145
146 const Router& vh2 = middleware::VHost("atlas.home.vchrist.at:8088");
147 vh2.get("/",
148 [] MIDDLEWARE(req, res, next) {
149 if (req->query("how").empty()) {
150 next();
151 } else if (req->query("how") == "route") {
152 next("route");
153 } else if (req->query("how") == "router") {
154 next("router");
155 }
156 })
157 .get([] APPLICATION(req, res) {
158 res->send("Hello! I am VHOST atlas.home.vchrist.at.");
159 });
160 tlsApp.use(vh2);
161
162 const Router& vh3 = middleware::VHost("ceres.home.vchrist.at:8088");
163 vh3.get("/",
164 [] MIDDLEWARE(req, res, next) {
165 if (req->query("how").empty()) {
166 next();
167 } else if (req->query("how") == "route") {
168 next("route");
169 } else if (req->query("how") == "router") {
170 next("router");
171 }
172 })
173 .get([] APPLICATION(req, res) {
174 res->send("Hello! I am VHOST ceres.home.vchrist.at.");
175 });
176 vh3.get("/", [] APPLICATION(req, res) {
177 res->send("Hello, next route on ceres.home.vchrist.at");
178 });
179 vh3.get("/test", [] APPLICATION(req, res) {
180 res->send("Test Route on VHOST ceres.home.vchrist.at.");
181 });
182 tlsApp.use(vh3);
183
184 tlsApp.use([] APPLICATION(req, res) {
185 res->status(404).send("The requested resource is not found.");
186 });
187
188 tlsApp.listen(8088,
189 [instanceName = tlsApp.getConfig()->getInstanceName()](const legacy::in6::WebApp::SocketAddress& socketAddress,
190 const core::socket::State& state) {
191 switch (state) {
192 case core::socket::State::OK:
193 VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'";
194 break;
195 case core::socket::State::DISABLED:
196 VLOG(1) << instanceName << " disabled";
197 break;
198 case core::socket::State::ERROR:
199 LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what();
200 break;
201 case core::socket::State::FATAL:
202 LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what();
203 break;
204 }
205 });
206
207 tlsApp.getConfig()->setCert("/home/voc/projects/snodec/snode.c/certs/wildcard.home.vchrist.at_-_snode.c_-_server.pem");
208 tlsApp.getConfig()->setCertKey(
209 "/home/voc/projects/snodec/snode.c/certs/Volker_Christian_-_Web_-_snode.c_-_server.key.encrypted.pem");
210 tlsApp.getConfig()->setCertKeyPassword("snode.c");
211 }
212
214}
#define APPLICATION(req, res)
Definition Router.h:68
#define MIDDLEWARE(req, res, next)
Definition Router.h:63
Route & use(const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &lambda) const
Definition Route.cpp:102
Route & use(const Router &router) const
Definition Router.cpp:100
Route & get(const Router &router) const
Definition Router.cpp:102
typename Server::SocketAddress SocketAddress
Definition WebAppT.h:68
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 ConfigRoot configRoot
Definition Config.h:116
WebAppT< web::http::legacy::in6::Server > WebApp
Definition WebApp.h:54
class VHost & VHost(const std::string &host)
Definition VHost.cpp:102
WebAppT< web::http::tls::in6::Server > WebApp
Definition WebApp.h:54

References utils::Config::configRoot, core::socket::State::DISABLED, core::socket::State::ERROR, logger::ERROR, core::socket::State::FATAL, logger::FATAL, core::socket::Socket< ConfigT >::getConfig(), subcommand::ConfigWWW::getHtmlRoot(), net::config::ConfigInstance::getInstanceName(), utils::SubCommand::getSubCommand(), express::WebApp::init(), net::in6::stream::SocketServer< SocketAcceptorT, ConfigSocketServerT, SocketContextFactoryT, Args >::listen(), logger::LogMessage::LogMessage(), utils::SubCommand::newSubCommand(), core::socket::State::OK, express::Next::operator()(), express::Request::query(), express::Response::send(), net::config::ConfigTls::setCert(), net::config::ConfigTls::setCertKey(), net::config::ConfigTls::setCertKeyPassword(), express::WebApp::start(), express::Response::status(), net::in6::SocketAddress::toString(), express::WebAppT< ServerT >::WebAppT(), and core::socket::State::what().

Here is the call graph for this function: