fix: automatic opening of admin-panel fails if a specific listen_interface is configured #892
Massimo Melina committed
Feb 8, 2025 at 14:59 UTC
58ba5c181a8f87c93bac6829b4ed8e5ef74e3463
1 file changed
+11
-6
src/listen.ts
+11
-6
@@ -70,7 +70,10 @@ export function openAdmin() {
70
for (const srv of [httpSrv, httpsSrv]) {
71
const a = srv?.address()
72
if (!a || typeof a === 'string') continue
73
- const baseUrl = srv!.name + '://localhost:' + a.port
73
+ const i = listenInterface.get()
74
+ // open() will fail with ::1, don't know why, as my browser correctly opens the resulting url
75
+ const hostname = i === '::1' || i in genericInterfaceNames ? 'localhost' : i
76
+ const baseUrl = `${srv!.name}://${hostname}:${a.port}`
77
open(baseUrl + ADMIN_URI, { wait: true}).catch(async e => {
78
console.debug(String(e))
79
console.warn("cannot launch browser on this machine >PLEASE< open your browser and reach one of these (you may need a different address)",
@@ -176,12 +179,14 @@ export const httpsPortCfg = defineConfig('https_port', PORT_DISABLED)
179
httpsPortCfg.sub(considerHttps)
180
listenInterface.sub(considerHttps)
181
182
+const genericInterfaceNames = {
183
+ '0.0.0.0': "any IPv4",
184
+ '::': "any IPv6",
185
+ '': "any network",
186
+}
187
+
188
function renderHost(host: string) {
180
- return xlate(host, {
181
- '0.0.0.0': "any IPv4",
182
- '::': "any IPv6",
183
- '': "any network",
184
- })
189
+ return xlate(host, genericInterfaceNames)
190
}
191
192
interface StartServer { port: number, host?:string }