Files
uWebSockets/examples/ServerName.cpp
T

34 lines
883 B
C++

#include "App.h"
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */
int main() {
/* Overly simple hello world app (SNI) */
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!");
}).listen(3000, [](auto *token) {
if (token) {
std::cout << "Listening on port " << 3000 << std::endl;
}
});
app.run();
std::cout << "Failed to listen on port 3000" << std::endl;
}