fix: inconsistent behaviour changing https_port

Massimo Melina committed Jan 22, 2022 at 00:02 UTC 1b3fbe59b8aaa73e1e35ce19fe3209c7db03a4b1
1 file changed +7 -5
src/listen.ts
+7 -5
@@ -47,20 +47,22 @@ subscribeConfig({ k:'private_key' }, async (v: string) => {
47 })
48
49 const CFG_HTTPS_PORT = 'https_port'
50 -subscribeConfig({ k:CFG_HTTPS_PORT, defaultValue: 443 }, considerHttps)
50 +subscribeConfig({ k:CFG_HTTPS_PORT }, considerHttps)
51
52 async function considerHttps() {
53 - if (!cert || !key)
54 - return stopServer(httpsSrv)
53 + await stopServer(httpsSrv)
54 + const port = getConfig('https_port') ?? 443
55 httpsSrv = https.createServer({ key, cert }, app.callback());
56 - return await startServer(httpsSrv, getConfig('https_port'), 's')
56 + return await startServer(httpsSrv, !cert || !key ? -1 : port, 's')
57 }
58
59 function startServer(srv: http.Server, port: number, secure:string='') {
60 return new Promise((resolve, reject) => {
61 try {
62 - if (port < 0)
62 + if (port < 0) {
63 + console.log('http'+secure+' off')
64 return resolve(null)
65 + }
66 srv.listen(port, () => {
67 const proto = 'http' + secure
68 const ad = srv.address()