// needs a function O webServe(S uri, SS params) { ... } // and a function newWebSocket() switchable int httpPort = 80; switchable int httpsPort = 443; transient autoDispose WebSocketHTTPD httpServer; transient autoDispose WebSocketHTTPD httpsServer; switchable bool redirectHttpToHttps; transient new HTTPSpamBlocker1 spamBlocker; void start_webServers(File keyStore, S passphrase) { start_webServers(serveHttps_makeSSLSocketFactory(keyStore, passphrase)); } void start_webServers(SSLServerSocketFactory sslSocketFactory) ctex { if (httpPort != 0) pcall { WebSocketHTTPD _httpServer = new(httpPort, lambda1 newWebSocket); _httpServer.enter = lambda0 enter; _httpServer.serveFunction = func(S uri, SS parms) { redirectHttpToHttps && !startsWith(uri, "/.well-known/") ? serveRedirect("https://" + serveHttp_domainName() + (httpsPort == 443 ? "" : ":" + httpsPort) + uri) : webServe(uri, parms) }; _httpServer.start(); print("HTTP server started on port " + _httpServer.getPort()); httpServer = _httpServer; } if (httpsPort == 0 || sslSocketFactory == null) ret; pcall { WebSocketHTTPD _httpsServer = new(httpsPort, lambda1 newWebSocket); _httpsServer.enter = lambda0 enter; _httpsServer.makeSecure(sslSocketFactory); _httpsServer.serveFunction = func(S uri, SS parms) { webServe(uri, parms) }; _httpsServer.start(); print("HTTPS server started on port " + _httpsServer.getPort()); httpsServer = _httpsServer; } } Cl webServers() { ret llNotNulls(httpServer, httpsServer); }