Skip to content

Commit

Permalink
Add hook for configuring ssl after 443 listen
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gilbert committed Oct 8, 2024
1 parent c9ad619 commit 679e6bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bin/start/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 1 addition & 4 deletions shared/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default function Server({
...o
} = {}) {
let uws
, isSsl
, handle
, wrapper

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 679e6bb

Please sign in to comment.