better code

Massimo Melina committed Aug 24, 2023 at 16:51 UTC 15de6fd7cce8e5b574a37fd7ee3d2db625cffd33
1 file changed +4 -3
src/listen.ts
+4 -3
@@ -63,7 +63,7 @@ const considerHttps = debounceAsync(async () => {
63 while (!app)
64 await wait(100)
65 httpsSrv = Object.assign(
66 - https.createServer(port < 0 ? {} : { key: httpsOptions.private_key, cert: httpsOptions.cert }, app.callback()),
66 + https.createServer(port === PORT_DISABLED ? {} : { key: httpsOptions.private_key, cert: httpsOptions.cert }, app.callback()),
67 { name: 'https' }
68 )
69 if (port >= 0) {
@@ -120,7 +120,8 @@ for (const cfg of httpsNeeds) {
120 })
121 }
122
123 -export const httpsPortCfg = defineConfig('https_port', -1)
123 +const PORT_DISABLED = -1
124 +export const httpsPortCfg = defineConfig('https_port', PORT_DISABLED)
125 httpsPortCfg.sub(considerHttps)
126
127 interface StartServer { port: number, host?:string }
@@ -128,7 +129,7 @@ function startServer(srv: typeof httpSrv, { port, host }: StartServer) {
129 return new Promise<number>(async resolve => {
130 if (!srv) return 0
131 try {
131 - if (port < 0 || !host && !await testIpV4()) // !host means ipV4+6, and if v4 port alone is busy we won't be notified of the failure, so we'll first test it on its own
132 + if (port === PORT_DISABLED || !host && !await testIpV4()) // !host means ipV4+6, and if v4 port alone is busy we won't be notified of the failure, so we'll first test it on its own
133 return resolve(0)
134 // from a few tests, this seems enough to support the expect-100 http/1.1 mechanism, at least with curl -T, not used by chrome|firefox anyway
135 srv.on('checkContinue', (req, res) => srv.emit('request', req, res))