handle bad certificate/key file

Massimo Melina committed Feb 13, 2022 at 17:44 UTC e37f2544b0e4ce6fe472b21744c81a3c5fbdc8f1
1 file changed +9 -1
src/listen.ts
+9 -1
@@ -83,7 +83,15 @@ subscribeConfig({ k:CFG_HTTPS_PORT, defaultValue: -1 }, considerHttps)
83
84 async function considerHttps() {
85 await stopServer(httpsSrv)
86 - httpsSrv = https.createServer({ key, cert }, app.callback())
86 + try {
87 + httpsSrv = https.createServer({ key, cert }, app.callback())
88 + httpsSrv.error = undefined
89 + }
90 + catch(e) {
91 + httpsSrv.error = "bad private key or certificate"
92 + console.log("failed to create https server: check your private key and certificate", String(e))
93 + return
94 + }
95 const port = await startServer(httpsSrv, {
96 port: !cert || !key ? -1 : getConfig('https_port'),
97 name: 'https'