Add per-SNI HttpRouter support (initial)

This commit is contained in:
Alex Hultman
2022-09-26 00:22:30 +02:00
parent c77cae4635
commit b1b931edfc
5 changed files with 49 additions and 37 deletions
+10 -30
View File
@@ -2,46 +2,26 @@
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */
struct us_listen_socket_t *globalListenSocket;
int main() {
/* Overly simple hello world app (SNI) */
/* The SSL context given in SSLApp constructor is the default / catch-all context */
uWS::SSLApp app = uWS::SSLApp({
.key_file_name = "misc/key.pem",
.cert_file_name = "misc/cert.pem",
.passphrase = "1234"
}).missingServerName([&app](const char *hostname) {
printf("We are missing server name: <%s>\n", hostname);
/* Assume it is localhost, so add it */
app.addServerName("localhost", {
.key_file_name = "../misc/key.pem",
.cert_file_name = "../misc/cert.pem",
.passphrase = "1234"
});
}).get("/*", [](auto *res, auto */*req*/) {
res->end("Hello world!");
}).get("/exit", [](auto *res, auto */*req*/) {
res->end("Shutting down!");
/* We use this to check graceful closedown */
us_listen_socket_close(1, globalListenSocket);
res->end("Hello from catch-all context!");
}).addServerName("*.google.*", {
/* Following is the context for *.google.* domain */
.key_file_name = "misc/key.pem",
.cert_file_name = "misc/cert.pem",
.passphrase = "1234"
}).domain("*.google.*").get("/*", [](auto *res, auto */*req*/) {
res->end("Hello from *.google.* context!");
}).listen(3000, [](auto *listenSocket) {
if (listenSocket) {
std::cout << "Listening on port " << 3000 << std::endl;
globalListenSocket = listenSocket;
} else {
std::cout << "Failed to listen on port 3000" << std::endl;
}
});
/* Let's add a wildcard SNI to begin with */
app.addServerName("*.google.*", {
.key_file_name = "../misc/key.pem",
.cert_file_name = "../misc/cert.pem",
.passphrase = "1234"
});
app.run();
}).run();
}