Improve app URL detection

This commit is contained in:
Garrett Mills 2022-06-07 22:03:05 -05:00
parent 1d717e0eb9
commit 48ce1bfa2f
2 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@extollo/lib", "name": "@extollo/lib",
"version": "0.9.44", "version": "0.9.45",
"description": "The framework library that lifts up your code.", "description": "The framework library that lifts up your code.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@ -169,11 +169,20 @@ export class Routing extends Unit {
public getAppUrl(): UniversalPath { public getAppUrl(): UniversalPath {
if ( this.request.has() ) { if ( this.request.has() ) {
// If we have a request context, use that URL, as it is the most reliable
const request = this.request.get() const request = this.request.get()
this.logging.debug(`url: ${request.url} | fullUrl: ${request.fullUrl}`) const url = new URL(request.fullUrl)
return universalPath(url.origin)
} }
const rawHost = String(this.config.get('server.url', 'http://localhost')).toLowerCase() const urlOverride = String(this.config.get('server.url', '')).toLowerCase()
if ( urlOverride ) {
// If the config has a URL override explicitly set, use that
return universalPath(urlOverride)
}
// Otherwise, try to build one from the host and port
const rawHost = String(this.config.get('server.host', 'http://localhost')).toLowerCase()
const isSSL = rawHost.startsWith('https://') const isSSL = rawHost.startsWith('https://')
const port = this.config.get('server.port', 8000) const port = this.config.get('server.port', 8000)