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

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

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

67 {
68 // Add config entries for the server to the config system befor init so they are available immediately
70
71 WebApp::init(argc, argv);
72
74
75 const legacy::in6::WebApp legacyServer("legacy");
76
77 const Router& router1 = middleware::VHost("localhost:8080");
78
79 const Router& ba = middleware::BasicAuthentication("voc", "pentium5", "Authenticate yourself with username and password");
80 ba.use(middleware::StaticMiddleware(utils::Config::configRoot.getSubCommand<subcommand::ConfigWWW>()->getHtmlRoot()));
81
82 router1.use(ba);
83 legacyServer.use(router1);
84
85 const Router& router2 = middleware::VHost("jupiter.home.vchrist.at:8080");
86 router2.get("/", [] APPLICATION(req, res) {
87 res->send("Hello! I am VHOST jupiter.home.vchrist.at.");
88 });
89 legacyServer.use(router2);
90
91 legacyServer.use([] APPLICATION(req, res) {
92 res->status(404).send("The requested resource is not found.");
93 });
94
95 legacyServer.listen(8080,
96 [instanceName = legacyServer.getConfig()->getInstanceName()](
97 const legacy::in6::WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
98 switch (state) {
99 case core::socket::State::OK:
100 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
101 break;
102 case core::socket::State::DISABLED:
103 VLOG(1) << instanceName << ": disabled";
104 break;
105 case core::socket::State::ERROR:
106 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
107 break;
108 case core::socket::State::FATAL:
109 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
110 break;
111 }
112 });
113
115
116 const express::tls::in6::WebApp tlsServer("tls");
117
118 const Router& vh1 = middleware::VHost("localhost:8088");
119 vh1.use(getRouter(utils::Config::configRoot.getSubCommand<subcommand::ConfigWWW>()->getHtmlRoot()));
120 tlsServer.use(vh1);
121
122 const Router& vh2 = middleware::VHost("jupiter.home.vchrist.at:8088");
123 vh2.get("/", [] APPLICATION(req, res) {
124 res->send("Hello! I am VHOST jupiter.home.vchrist.at.");
125 });
126
127 tlsServer.use(vh2);
128
129 tlsServer.use([] APPLICATION(req, res) {
130 res->status(404).send("The requested resource is not found.");
131 });
132
133 tlsServer.listen(8088, [](const legacy::in6::WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
134 switch (state) {
136 VLOG(1) << "tls: listening on '" << socketAddress.toString() << "'"
137 << "'";
138 break;
140 VLOG(1) << "tls: disabled";
141 break;
143 VLOG(1) << "tls: error occurred";
144 break;
146 VLOG(1) << "tls: fatal error occurred";
147 break;
148 }
149 });
150
152}
#define VLOG(level)
Definition Logger.h:164
#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: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
static express::Router getRouter()
Definition servers.h:68
WebAppT< web::http::legacy::in6::Server > WebApp
Definition WebApp.h:54
class VHost & VHost(const std::string &host)
Definition VHost.cpp:102
class BasicAuthentication & BasicAuthentication(const std::string &userName, const std::string &password, const std::string &realm)
WebAppT< web::http::tls::in6::Server > WebApp
Definition WebApp.h:54

References express::middleware::BasicAuthentication::BasicAuthentication, 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(), getRouter(), 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::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: