improve makeServerUrl to eliminate ':port' when port is empty
This commit is contained in:
parent
64527f727d
commit
3e186ad46a
19
unitool.js
19
unitool.js
@ -151,24 +151,11 @@ export default {
|
|||||||
return route
|
return route
|
||||||
}
|
}
|
||||||
|
|
||||||
let hostname = envar.servHostname
|
const hostname = envar.servHostname || globalThis.window?.location?.hostname || 'localhost'
|
||||||
let port = envar.servPort
|
const port = envar.servPort || globalThis.window?.location?.port || ''
|
||||||
// #ifdef H5
|
|
||||||
if (!hostname) {
|
|
||||||
hostname = window?.location?.hostname
|
|
||||||
}
|
|
||||||
if (!port) {
|
|
||||||
port = window?.location?.port?.replace(':', '')
|
|
||||||
}
|
|
||||||
// #endif
|
|
||||||
if (!hostname) {
|
|
||||||
// 如果没有配置 envar.servHostname,又不是在 H5 环境,则最后的默认值是 localhost
|
|
||||||
hostname = 'localhost'
|
|
||||||
}
|
|
||||||
|
|
||||||
const protocol = hostname === 'localhost' ? 'http' : envar.servProtocol || (process.env.NODE_ENV === 'production' ? 'https' : 'http')
|
const protocol = hostname === 'localhost' ? 'http' : envar.servProtocol || (process.env.NODE_ENV === 'production' ? 'https' : 'http')
|
||||||
|
|
||||||
return `${protocol}://${hostname}:${port}/${route.replace(/^\//, '')}`
|
return `${protocol}://${hostname}${port ? ':' : ''}${port}/${route.replace(/^\//, '')}`
|
||||||
},
|
},
|
||||||
|
|
||||||
makeBgUrl (path) {
|
makeBgUrl (path) {
|
||||||
|
Loading…
Reference in New Issue
Block a user