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 "express/legacy/in6/WebApp.h"
43#include "express/middleware/StaticMiddleware.h"
44#include "express/middleware/VHost.h"
45#include "express/tls/in6/WebApp.h"
46#include "utils/Config.h"
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
50#include "log/Logger.h"
56using namespace express;
61 router.use(middleware::StaticMiddleware(webRoot));
66int main(
int argc,
char* argv[]) {
67 utils::Config::addStringOption(
"--web-root",
"Root directory of the web site",
"[path]");
72 const legacy::
in6::WebApp legacyApp
("legacy");
74 const Router& vh1 = middleware::VHost(
"localhost:8080");
75 vh1.use(middleware::StaticMiddleware(utils::Config::getStringOptionValue(
"--web-root")));
78 const Router& vh2 = middleware::VHost(
"atlas.home.vchrist.at:8080");
81 if (req->
query("how").empty()) {
83 }
else if (req->
query("how") ==
"route") {
85 }
else if (req->
query("how") ==
"router") {
90 res->
send("Hello! I am VHOST atlas.home.vchrist.at.");
94 const Router& vh3 = middleware::VHost(
"ceres.home.vchrist.at:8080");
97 if (req->
query("how").empty()) {
99 }
else if (req->
query("how") ==
"route") {
101 }
else if (req->
query("how") ==
"router") {
106 res->
send("Hello! I am VHOST ceres.home.vchrist.at.");
109 res->
send("Hello, next route on ceres.home.vchrist.at");
112 res->
send("Test Route on VHOST ceres.home.vchrist.at.");
122 const core::socket::
State& state) {
125 VLOG(1) << instanceName <<
" listening on '" << socketAddress
.toString() <<
"'";
128 VLOG(1) << instanceName <<
" disabled";
131 LOG(ERROR) << instanceName <<
" " << socketAddress
.toString() <<
": " << state
.what();
134 LOG(FATAL) << instanceName <<
" " << socketAddress
.toString() <<
": " << state
.what();
141 const express::tls::
in6::WebApp tlsApp
("tls");
143 const Router& vh1 = middleware::VHost(
"localhost:8088");
144 vh1.use(middleware::StaticMiddleware(utils::Config::getStringOptionValue(
"--web-root")));
147 const Router& vh2 = middleware::VHost(
"atlas.home.vchrist.at:8088");
150 if (req->
query("how").empty()) {
152 }
else if (req->
query("how") ==
"route") {
154 }
else if (req->
query("how") ==
"router") {
159 res->
send("Hello! I am VHOST atlas.home.vchrist.at.");
163 const Router& vh3 = middleware::VHost(
"ceres.home.vchrist.at:8088");
166 if (req->
query("how").empty()) {
168 }
else if (req->
query("how") ==
"route") {
170 }
else if (req->
query("how") ==
"router") {
175 res->
send("Hello! I am VHOST ceres.home.vchrist.at.");
178 res->
send("Hello, next route on ceres.home.vchrist.at");
181 res->
send("Test Route on VHOST ceres.home.vchrist.at.");
191 const core::socket::
State& state) {
194 VLOG(1) << instanceName <<
" listening on '" << socketAddress
.toString() <<
"'";
197 VLOG(1) << instanceName <<
" disabled";
200 LOG(ERROR) << instanceName <<
" " << socketAddress
.toString() <<
": " << state
.what();
203 LOG(FATAL) << instanceName <<
" " << socketAddress
.toString() <<
": " << state
.what();
208 tlsApp
.getConfig().setCert("/home/voc/projects/snodec/snode.c/certs/wildcard.home.vchrist.at_-_snode.c_-_server.pem");
210 "/home/voc/projects/snodec/snode.c/certs/Volker_Christian_-_Web_-_snode.c_-_server.key.encrypted.pem");
#define APPLICATION(req, res)
#define MIDDLEWARE(req, res, next)
Config & getConfig() const
static constexpr int DISABLED
static constexpr int ERROR
static constexpr int FATAL
void operator()(const std::string &how="") const
const std::string & query(const std::string &key) const
void send(const std::string &chunk)
Response & status(int status)
WebAppT(const std::string &name)
static void init(int argc, char *argv[])
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
const std::string & getInstanceName() const
ConfigTls & setCert(const std::string &cert)
ConfigTls & setCertKey(const std::string &certKey)
ConfigTls & setCertKeyPassword(const std::string &certKeyPassword)
std::string toString(bool expanded=true) const override
void listen(uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
int main(int argc, char *argv[])
Router getRouter(const std::string &webRoot)