fix: admin-panel at boot could report a false positive for the certificate
Massimo Melina committed
May 3, 2023 at 14:10 UTC
ec6b96414fcc314ffaef11762b2148305b42fa9e
2 files changed
+5
-3
src/listen.ts
+1
-1
@@ -105,7 +105,7 @@ for (const cfg of httpsNeeds) {
105
unwatch = watchLoad(v, data => {
106
httpsOptions[k] = data
107
considerHttps()
108
- }).unwatch
108
+ }, { immediateFirst: true }).unwatch
109
await considerHttps()
110
})
111
}
src/watchLoad.ts
+4
-2
@@ -7,11 +7,11 @@ import { debounceAsync, readFileBusy } from './misc'
7
8
export type WatchLoadCanceller = () => void
9
10
-interface Options { failedOnFirstAttempt?: ()=>void }
10
+interface Options { failedOnFirstAttempt?: ()=>void, immediateFirst?: boolean }
11
12
type WriteFile = typeof fs.writeFile
13
interface WatchLoadReturn { unwatch:WatchLoadCanceller, save:WriteFile }
14
-export function watchLoad(path:string, parser:(data:any)=>void|Promise<void>, { failedOnFirstAttempt }:Options={}): WatchLoadReturn {
14
+export function watchLoad(path:string, parser:(data:any)=>void|Promise<void>, { failedOnFirstAttempt, immediateFirst }:Options={}): WatchLoadReturn {
15
let doing = false
16
let watcher: FSWatcher | undefined
17
const debounced = debounceAsync(load, 500, { maxWait: 1000 })
@@ -35,6 +35,8 @@ export function watchLoad(path:string, parser:(data:any)=>void|Promise<void>, {
35
debounced().then()
36
})
37
debounced().catch(x=>x)
38
+ if (immediateFirst)
39
+ debounced.flush().then()
40
}
41
catch(e) {
42
retry = setTimeout(install, 3_000) // manual watching until watch is successful