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

60 {
61 const Router router;
62
63 router.use(middleware::BasicAuthentication("voc", "pentium5", "Authenticate yourself with username and password"));
65
66 return router;
67}
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 69 of file testbasicauthentication.cpp.

69 {
71
72 WebApp::init(argc, argv);
73
74 {
75 const legacy::in6::WebApp legacyApp("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");
81
82 router1.use(ba);
83 legacyApp.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 legacyApp.use(router2);
90
91 legacyApp.use([] APPLICATION(req, res) {
92 res->status(404).send("The requested resource is not found.");
93 });
94
95 legacyApp.listen(8080,
96 [instanceName = legacyApp.getConfig().getInstanceName()](const legacy::in6::WebApp::SocketAddress& socketAddress,
97 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
114 {
115 const express::tls::in6::WebApp tlsApp("tls");
116
117 const Router& vh1 = middleware::VHost("localhost:8088");
119 tlsApp.use(vh1);
120
121 const Router& vh2 = middleware::VHost("jupiter.home.vchrist.at:8088");
122 vh2.get("/", [] APPLICATION(req, res) {
123 res->send("Hello! I am VHOST jupiter.home.vchrist.at.");
124 });
125
126 tlsApp.use(vh2);
127
128 tlsApp.use([] APPLICATION(req, res) {
129 res->status(404).send("The requested resource is not found.");
130 });
131
132 tlsApp.listen(8088, [](const legacy::in6::WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
133 switch (state) {
135 VLOG(1) << "tls: listening on '" << socketAddress.toString() << "'"
136 << "'";
137 break;
139 VLOG(1) << "tls: disabled";
140 break;
142 VLOG(1) << "tls: error occurred";
143 break;
145 VLOG(1) << "tls: fatal error occurred";
146 break;
147 }
148 });
149 }
150 }
151
153}
#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: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 T * addInstance()
static T * getInstance()
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 utils::Config::addInstance(), express::middleware::BasicAuthentication::BasicAuthentication, core::socket::State::DISABLED, core::socket::State::ERROR, core::socket::State::FATAL, core::socket::Socket< ConfigT >::getConfig(), instance::ConfigWWW::getHtmlRoot(), utils::Config::getInstance(), 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: