fix: puzzling console error on headless machines
Massimo Melina committed
Jun 22, 2022 at 11:10 UTC
cbffdfa9aa7ead9bd8ba03db1c0eb7e80c7142f3
1 file changed
+6
-2
server/src/listen.ts
+6
-2
@@ -29,7 +29,11 @@ portCfg.sub(async port => {
29
httpSrv.on('connection', newConnection)
30
printUrls(port, 'http')
31
if (openBrowserAtStart.get())
32
- open('http://localhost' + (port === 80 ? '' : ':' + port) + ADMIN_URI).then()
32
+ open('http://localhost' + (port === 80 ? '' : ':' + port) + ADMIN_URI, { wait: true}).catch(e => {
33
+ console.debug(String(e))
34
+ console.warn("cannot launch browser on this machine >PLEASE< open your browser and reach one of these (you may need a different address)",
35
+ ...Object.values(getUrls()).flat().map(x => '\n - ' + x + ADMIN_URI))
36
+ })
37
})
38
39
const considerHttps = debounceAsync(async () => {
@@ -169,7 +173,7 @@ const ignore = /^(lo|.*loopback.*|virtualbox.*|.*\(wsl\).*)$/i // avoid giving t
173
174
export function getUrls() {
175
return Object.fromEntries(onlyTruthy([httpSrv, httpsSrv].map(srv => {
172
- if (!srv.listening)
176
+ if (!srv?.listening)
177
return false
178
const port = (srv?.address() as any)?.port
179
const appendPort = port === (srv.name === 'https' ? 443 : 80) ? '' : ':' + port