fix(Maps): add x-forwarded-proto support to handle https termination (#600)

This commit is contained in:
David Gross 2026-04-01 16:28:11 -06:00 committed by GitHub
parent 85359376a2
commit 31d4f9c661
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View File

@ -95,7 +95,13 @@ export default class MapsController {
})
}
const styles = await this.mapService.generateStylesJSON(request.host(), request.protocol())
const forwardedProto = request.headers()['x-forwarded-proto'];
const protocol: string = forwardedProto
? (typeof forwardedProto === 'string' ? forwardedProto : request.protocol())
: request.protocol();
const styles = await this.mapService.generateStylesJSON(request.host(), protocol)
return response.json(styles)
}

View File

@ -526,8 +526,20 @@ export class MapService implements IMapService {
}
}
const host = specifiedHost || getHost()
const withProtocol = host.startsWith('http') ? host : `${protocol}://${host}`
function specifiedHostOrDefault() {
if(specifiedHost === null) {
return getHost()
}
try {
const specifiedUrl = new URL(specifiedHost)
return specifiedUrl.host
} catch (error) {
return getHost()
}
}
const host = specifiedHostOrDefault();
const withProtocol = `${protocol}://${host}`
const baseUrlPath =
process.env.NODE_ENV === 'production' ? childPath : urlJoin(this.mapStoragePath, childPath)