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/BasicAuthentication.h"
44#include "express/middleware/StaticMiddleware.h"
45#include "express/middleware/VHost.h"
46#include "express/tls/in6/WebApp.h"
47#include "utils/Config.h"
49#ifndef DOXYGEN_SHOULD_SKIP_THIS
51#include "log/Logger.h"
57using namespace express;
63 router.use(middleware::StaticMiddleware(webRoot));
68int main(
int argc,
char* argv[]) {
69 utils::Config::addStringOption(
"--web-root",
"Root directory of the web site",
"[path]");
74 const legacy::
in6::WebApp legacyApp
("legacy");
76 const Router& router1 = middleware::VHost(
"localhost:8080");
79 ba.use(middleware::StaticMiddleware(utils::Config::getStringOptionValue(
"--web-root")));
82 legacyApp.use(router1);
84 const Router& router2 = middleware::VHost(
"ceres.home.vchrist.at:8080");
86 res->
send("Hello! I am VHOST ceres.home.vchrist.at.");
88 legacyApp.use(router2);
96 const core::socket::
State& state) {
99 VLOG(1) << instanceName <<
": listening on '" << socketAddress
.toString() <<
"'";
102 VLOG(1) << instanceName <<
": disabled";
105 LOG(ERROR) << instanceName <<
": " << socketAddress
.toString() <<
": " << state
.what();
108 LOG(FATAL) << instanceName <<
": " << socketAddress
.toString() <<
": " << state
.what();
114 const express::tls::
in6::WebApp tlsApp
("tls");
116 const Router& vh1 = middleware::VHost(
"localhost:8088");
117 vh1.use(
getRouter(utils::Config::getStringOptionValue(
"--web-root")
));
120 const Router& vh2 = middleware::VHost(
"ceres.home.vchrist.at:8088");
122 res->
send("Hello! I am VHOST ceres.home.vchrist.at.");
131 tlsApp
.listen(8088
, [](
const legacy::
in6::WebApp::SocketAddress& socketAddress,
const core::socket::
State& state) {
134 VLOG(1) <<
"tls: listening on '" << socketAddress
.toString() <<
"'"
138 VLOG(1) <<
"tls: disabled";
141 VLOG(1) <<
"tls: error occurred";
144 VLOG(1) <<
"tls: fatal error occurred";
#define APPLICATION(req, res)
Config & getConfig() const
static constexpr int DISABLED
static constexpr int ERROR
static constexpr int FATAL
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})
friend class BasicAuthentication & BasicAuthentication(const std::string &userName, const std::string &password, const std::string &realm)
const std::string & getInstanceName() const
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)