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 59 of file testbasicauthentication.cpp.

59 {
60 const Router router;
61
62 router.use(middleware::BasicAuthentication("voc", "pentium5", "Authenticate yourself with username and password"));
64
65 return router;
66}
Route & use(const Router &router) const
Definition Router.cpp:88
Router router(database::mariadb::MariaDBClient &db)
Definition testregex.cpp:68

References express::middleware::BasicAuthentication::BasicAuthentication.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

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

Definition at line 68 of file testbasicauthentication.cpp.

68 {
69 utils::Config::addStringOption("--web-root", "Root directory of the web site", "[path]");
70
71 WebApp::init(argc, argv);
72
73 {
74 const legacy::in6::WebApp legacyApp("legacy");
75
76 const Router& router1 = middleware::VHost("localhost:8080");
77
78 const Router& ba = middleware::BasicAuthentication("voc", "pentium5", "Authenticate yourself with username and password");
80
81 router1.use(ba);
82 legacyApp.use(router1);
83
84 const Router& router2 = middleware::VHost("ceres.home.vchrist.at:8080");
85 router2.get("/", [] APPLICATION(req, res) {
86 res->send("Hello! I am VHOST ceres.home.vchrist.at.");
87 });
88 legacyApp.use(router2);
89
90 legacyApp.use([] APPLICATION(req, res) {
91 res->status(404).send("The requested resource is not found.");
92 });
93
94 legacyApp.listen(8080,
95 [instanceName = legacyApp.getConfig().getInstanceName()](const legacy::in6::WebApp::SocketAddress& socketAddress,
96 const core::socket::State& state) {
97 switch (state) {
98 case core::socket::State::OK:
99 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
100 break;
101 case core::socket::State::DISABLED:
102 VLOG(1) << instanceName << ": disabled";
103 break;
104 case core::socket::State::ERROR:
105 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
106 break;
107 case core::socket::State::FATAL:
108 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
109 break;
110 }
111 });
112
113 {
114 const express::tls::in6::WebApp tlsApp("tls");
115
116 const Router& vh1 = middleware::VHost("localhost:8088");
118 tlsApp.use(vh1);
119
120 const Router& vh2 = middleware::VHost("ceres.home.vchrist.at:8088");
121 vh2.get("/", [] APPLICATION(req, res) {
122 res->send("Hello! I am VHOST ceres.home.vchrist.at.");
123 });
124
125 tlsApp.use(vh2);
126
127 tlsApp.use([] APPLICATION(req, res) {
128 res->status(404).send("The requested resource is not found.");
129 });
130
131 tlsApp.listen(8088, [](const legacy::in6::WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
132 switch (state) {
134 VLOG(1) << "tls: listening on '" << socketAddress.toString() << "'"
135 << "'";
136 break;
138 VLOG(1) << "tls: disabled";
139 break;
141 VLOG(1) << "tls: error occurred";
142 break;
144 VLOG(1) << "tls: fatal error occurred";
145 break;
146 }
147 });
148 }
149 }
150
152}
#define APPLICATION(req, res)
Definition Router.h:68
static constexpr int DISABLED
Definition State.h:56
static constexpr int ERROR
Definition State.h:57
static constexpr int FATAL
Definition State.h:58
static constexpr int OK
Definition State.h:55
Route & use(const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &lambda) const
Definition Route.cpp:131
Route & get(const Router &router) const
Definition Router.cpp:90
typename Server::SocketAddress SocketAddress
Definition WebAppT.h:70
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
static express::Router getRouter()
Definition servers.h:68
ssize_t send(int sockfd, const void *buf, std::size_t len, int flags)
Definition socket.cpp:96

References express::middleware::BasicAuthentication::BasicAuthentication, core::socket::State::DISABLED, core::socket::State::ERROR, core::socket::State::FATAL, core::socket::Socket< ConfigT >::getConfig(), net::config::ConfigInstance::getInstanceName(), getRouter(), express::WebApp::init(), net::in6::stream::SocketServer< SocketAcceptorT, ConfigSocketServerT, SocketContextFactoryT, Args >::listen(), core::socket::State::OK, express::Response::send(), 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: