From 679e6bb7ffd4e2ca3300ae933354e7da2e4497cf Mon Sep 17 00:00:00 2001 From: Gilbert Date: Tue, 8 Oct 2024 02:08:01 -0500 Subject: [PATCH] Add hook for configuring ssl after 443 listen This is for running addServerName(), which doesn't work before 443 listen because the current uws variable is a uWS.App instead of uWS.SSLApp. However, AFTER the 443 listen, uws gets reassigned to be the latter, making addServerName() work again. --- bin/start/serve.js | 2 ++ shared/server/index.js | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/start/serve.js b/bin/start/serve.js index 94946d6..4b436ab 100644 --- a/bin/start/serve.js +++ b/bin/start/serve.js @@ -65,6 +65,7 @@ async function listenHttp() { await redirect.listen(config.httpPort, config.address) console.log('HTTP Redirecting to HTTPS on', config.httpPort) // eslint-disable-line } else if (config.secure && config.ssl.mode === 'manual') { + router.route(Acme.route(isMainThread ? {} : { get: getFromParent })) await router.listen(config.httpPort, config.address) console.log('HTTP (manual ssl) listening on', config.httpPort) // eslint-disable-line } else { @@ -119,6 +120,7 @@ async function listenHttps() { isMainThread && config.acme.domains.length && await runAcme() sslListener && (sslListener.unlisten(), sslListener = null) sslListener = await router.listen(config.httpsPort, config.address, config.ssl) + server.configureSsl && await server.configureSsl(router) console.log('HTTPS Listening on', config.httpsPort) // eslint-disable-line } diff --git a/shared/server/index.js b/shared/server/index.js index 03c0623..4b057d4 100644 --- a/shared/server/index.js +++ b/shared/server/index.js @@ -12,7 +12,6 @@ export default function Server({ ...o } = {}) { let uws - , isSsl , handle , wrapper @@ -43,7 +42,6 @@ export default function Server({ return router function addServerName(name, options) { - if (!isSsl) return uws.addServerName(name, options) uws.domain(name).any('/*', wrapper) } @@ -127,8 +125,7 @@ export default function Server({ port = parseInt(port) wrapper = wrap - isSsl = !!(o.cert || o.mode === 'manual') - uws = isSsl + uws = !!(o.cert || o.mode === 'manual') ? uWS.SSLApp({ cert_file_name: o.cert, key_file_name: o.key, ...o }) : uWS.App(o) asn.forEach(xs => addServerName(...xs))