fix: port wasn't included for external-ip #581
Massimo Melina committed
May 5, 2024 at 23:46 UTC
7a34975b53d18b03a70a7b2531c2bc21ad2728bc
4 files changed
+8
-6
src/adminApis.ts
+1
-1
@@ -116,7 +116,7 @@ export const adminApis: ApiHandlers = {
116
platform: process.platform,
117
urls: await getUrls(),
118
ips: await getIps(false),
119
- baseUrl: getBaseUrlOrDefault(),
119
+ baseUrl: await getBaseUrlOrDefault(),
120
roots: roots.get(),
121
updatePossible: !await updateSupported() ? false : (await localUpdateAvailable()) ? 'local' : true,
122
proxyDetected: getProxyDetected(),
src/api.vfs.ts
+1
-1
@@ -128,7 +128,7 @@ const apis: ApiHandlers = {
128
simplifyName(child)
129
;(parentNode.children ||= []).unshift(child)
130
saveVfs()
131
- const link = rest.url ? undefined : getBaseUrlOrDefault()
131
+ const link = rest.url ? undefined : await getBaseUrlOrDefault()
132
+ (parent ? enforceFinal('/', parent) : '/')
133
+ encodeURIComponent(getNodeName(child))
134
+ (isDir ? '/' : '')
src/listen.ts
+2
-2
@@ -27,8 +27,8 @@ const openBrowserAtStart = defineConfig('open_browser_at_start', !DEV)
27
export const baseUrl = defineConfig('base_url', '',
28
x => /(?<=\/\/)[^\/]+/.exec(x)?.[0]) // compiled is host only
29
30
-export function getBaseUrlOrDefault() {
31
- return baseUrl.get() || defaultBaseUrl.get()
30
+export async function getBaseUrlOrDefault() {
31
+ return baseUrl.get() || await defaultBaseUrl.get()
32
}
33
34
export function getHttpsWorkingPort() {
src/nat.ts
+4
-2
@@ -17,9 +17,11 @@ export const defaultBaseUrl = proxy({
17
externalIp: '',
18
localIp: '',
19
port: 0,
20
- get() {
20
+ async get() {
21
const defPort = this.proto === 'https' ? 443 : 80
22
- return `${this.proto}://${ this.publicIps[0] || this.externalIp || this.localIp}${!this.port || this.port === defPort ? '' : ':' + this.port}`
22
+ const status = await getServerStatus()
23
+ const port = this.port || (this.proto === 'https' ? status.https.port : status.http.port)
24
+ return `${this.proto}://${ this.publicIps[0] || this.externalIp || this.localIp}${!port || port === defPort ? '' : ':' + port}`
25
}
26
})
27