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

37 {
38 const Router router;
39
40 router.use(middleware::BasicAuthentication("voc", "pentium5", "Authenticate yourself with username and password"));
42
43 return router;
44}
Route & use(const Router &router) const
Definition Router.cpp:60
Router router(database::mariadb::MariaDBClient &db)
Definition testregex.cpp:46

◆ main()

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

Definition at line 46 of file testbasicauthentication.cpp.

46 {
47 utils::Config::addStringOption("--web-root", "Root directory of the web site", "[path]");
48
49 WebApp::init(argc, argv);
50
51 {
52 const legacy::in6::WebApp legacyApp("legacy");
53
54 const Router& router1 = middleware::VHost("localhost:8080");
55
56 const Router& ba = middleware::BasicAuthentication("voc", "pentium5", "Authenticate yourself with username and password");
58
59 router1.use(ba);
60 legacyApp.use(router1);
61
62 const Router& router2 = middleware::VHost("ceres.home.vchrist.at:8080");
63 router2.get("/", [] APPLICATION(req, res) {
64 res->send("Hello! I am VHOST ceres.home.vchrist.at.");
65 });
66 legacyApp.use(router2);
67
68 legacyApp.use([] APPLICATION(req, res) {
69 res->status(404).send("The requested resource is not found.");
70 });
71
72 legacyApp.listen(8080,
73 [instanceName = legacyApp.getConfig().getInstanceName()](const legacy::in6::WebApp::SocketAddress& socketAddress,
74 const core::socket::State& state) {
75 switch (state) {
76 case core::socket::State::OK:
77 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
78 break;
79 case core::socket::State::DISABLED:
80 VLOG(1) << instanceName << ": disabled";
81 break;
82 case core::socket::State::ERROR:
83 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
84 break;
85 case core::socket::State::FATAL:
86 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
87 break;
88 }
89 });
90
91 {
92 const express::tls::in6::WebApp tlsApp("tls");
93
94 const Router& vh1 = middleware::VHost("localhost:8088");
96 tlsApp.use(vh1);
97
98 const Router& vh2 = middleware::VHost("ceres.home.vchrist.at:8088");
99 vh2.get("/", [] APPLICATION(req, res) {
100 res->send("Hello! I am VHOST ceres.home.vchrist.at.");
101 });
102
103 tlsApp.use(vh2);
104
105 tlsApp.use([] APPLICATION(req, res) {
106 res->status(404).send("The requested resource is not found.");
107 });
108
109 tlsApp.listen(8088, [](const legacy::in6::WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
110 switch (state) {
112 VLOG(1) << "tls: listening on '" << socketAddress.toString() << "'"
113 << "'";
114 break;
116 VLOG(1) << "tls: disabled";
117 break;
119 VLOG(1) << "tls: error occurred";
120 break;
122 VLOG(1) << "tls: fatal error occurred";
123 break;
124 }
125 });
126 }
127 }
128
130}
#define APPLICATION(req, res)
Definition Router.h:45
static constexpr int DISABLED
Definition State.h:34
static constexpr int ERROR
Definition State.h:35
static constexpr int FATAL
Definition State.h:36
static constexpr int OK
Definition State.h:33
Route & use(const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &lambda) const
Definition Route.cpp:78
Route & get(const Router &router) const
Definition Router.cpp:62
typename Server::SocketAddress SocketAddress
Definition WebAppT.h:48
static void init(int argc, char *argv[])
Definition WebApp.cpp:34
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Definition WebApp.cpp:38
static CLI::Option * addStringOption(const std::string &name, const std::string &description, const std::string &typeName)
Definition Config.cpp:862
static std::string getStringOptionValue(const std::string &name)
Definition Config.cpp:919
static express::Router getRouter()
Definition servers.h:46
ssize_t send(int sockfd, const void *buf, std::size_t len, int flags)
Definition socket.cpp:74
class VHost & VHost(const std::string &host)
Definition VHost.cpp:51
class BasicAuthentication & BasicAuthentication(const std::string &userName, const std::string &password, const std::string &realm)

References express::WebApp::init(), and express::WebApp::start().

Here is the call graph for this function: