getConfig will make use of defaultValue

Massimo Melina committed Jan 25, 2022 at 16:39 UTC b520bc5835ab458665597148f9d849295cd779fd
2 files changed +3 -3
src/config.ts
+1 -1
@@ -45,7 +45,7 @@ export function subscribeConfig({ k, ...definition }:{ k:string } & ConfigProps,
45 }
46
47 export function getConfig(k:string) {
48 - return state[k]
48 + return k in state ? state[k] : configProps[k]?.defaultValue
49 }
50
51 export function setConfig(newCfg: Record<string,any>) {
src/listen.ts
+2 -2
@@ -47,11 +47,11 @@ subscribeConfig({ k:'private_key' }, async (v: string) => {
47 })
48
49 const CFG_HTTPS_PORT = 'https_port'
50 -subscribeConfig({ k:CFG_HTTPS_PORT }, considerHttps)
50 +subscribeConfig({ k:CFG_HTTPS_PORT, defaultValue: 443 }, considerHttps)
51
52 async function considerHttps() {
53 await stopServer(httpsSrv)
54 - const port = getConfig('https_port') ?? 443
54 + const port = getConfig('https_port')
55 httpsSrv = https.createServer({ key, cert }, app.callback());
56 return await startServer(httpsSrv, !cert || !key ? -1 : port, 's')
57 }