diff --git a/Makefile b/Makefile index 4760962..0ab4d35 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -EXAMPLE_FILES := HelloWorld EchoServer BroadcastingEchoServer UpgradeSync UpgradeAsync +EXAMPLE_FILES := HelloWorld ServerName EchoServer BroadcastingEchoServer UpgradeSync UpgradeAsync THREADED_EXAMPLE_FILES := HelloWorldThreaded EchoServerThreaded override CXXFLAGS += -lpthread -Wconversion -std=c++17 -Isrc -IuSockets/src override LDFLAGS += uSockets/*.o -lz diff --git a/examples/ServerName.cpp b/examples/ServerName.cpp new file mode 100644 index 0000000..b2e139e --- /dev/null +++ b/examples/ServerName.cpp @@ -0,0 +1,24 @@ +#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({ + .key_file_name = "../misc/key.pem", + .cert_file_name = "../misc/cert.pem", + .passphrase = "1234" + }).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; + } + }).run(); + + std::cout << "Failed to listen on port 3000" << std::endl; +} diff --git a/src/App.h b/src/App.h index 048935a..18fe9aa 100644 --- a/src/App.h +++ b/src/App.h @@ -38,6 +38,13 @@ private: public: + /* Server name */ + TemplatedApp &&addServerName(std::string hostname_pattern, us_socket_context_options_t options = {}) { + + us_socket_context_add_server_name(SSL, (struct us_socket_context_t *) httpContext, hostname_pattern.c_str(), options); + return std::move(*this); + } + /* Returns the SSL_CTX of this app, or nullptr. */ void *getNativeHandle() { return us_socket_context_get_native_handle(SSL, (struct us_socket_context_t *) httpContext); diff --git a/uSockets b/uSockets index 716c51b..5c4116f 160000 --- a/uSockets +++ b/uSockets @@ -1 +1 @@ -Subproject commit 716c51be4447196d6818b212189bcf31698179c4 +Subproject commit 5c4116f2fadd52359b8c9b7364f4fc860d7dbf68