Add per-SNI HttpRouter support (initial)
This commit is contained in:
+10
-30
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user