From b65b6d6b356ce947687aed1ac070a1ae379ce1ce Mon Sep 17 00:00:00 2001 From: David Gross Date: Wed, 1 Apr 2026 16:28:11 -0600 Subject: [PATCH] fix(Maps): add x-forwarded-proto support to handle https termination (#600) --- admin/app/controllers/maps_controller.ts | 8 +++++++- admin/app/services/map_service.ts | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/admin/app/controllers/maps_controller.ts b/admin/app/controllers/maps_controller.ts index 9927a19..4a84307 100644 --- a/admin/app/controllers/maps_controller.ts +++ b/admin/app/controllers/maps_controller.ts @@ -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) } diff --git a/admin/app/services/map_service.ts b/admin/app/services/map_service.ts index 00f4976..483b215 100644 --- a/admin/app/services/map_service.ts +++ b/admin/app/services/map_service.ts @@ -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)