Skip to content

Commit 9220b4b

Browse files
committed
fix(maps): respect request protocol for reverse proxy HTTPS support
1 parent 6120e25 commit 9220b4b

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

admin/app/controllers/maps_controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default class MapsController {
8383
})
8484
}
8585

86-
const styles = await this.mapService.generateStylesJSON(request.host())
86+
const styles = await this.mapService.generateStylesJSON(request.host(), request.protocol())
8787
return response.json(styles)
8888
}
8989

admin/app/services/map_service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class MapService implements IMapService {
260260
}
261261
}
262262

263-
async generateStylesJSON(host: string | null = null): Promise<BaseStylesFile> {
263+
async generateStylesJSON(host: string | null = null, protocol: string = 'http'): Promise<BaseStylesFile> {
264264
if (!(await this.checkBaseAssetsExist())) {
265265
throw new Error('Base map assets are missing from storage/maps')
266266
}
@@ -281,8 +281,8 @@ export class MapService implements IMapService {
281281
* e.g. user is accessing from "example.com", but we would by default generate "localhost:8080/..." so maps would
282282
* fail to load.
283283
*/
284-
const sources = this.generateSourcesArray(host, regions)
285-
const baseUrl = this.getPublicFileBaseUrl(host, this.basemapsAssetsDir)
284+
const sources = this.generateSourcesArray(host, regions, protocol)
285+
const baseUrl = this.getPublicFileBaseUrl(host, this.basemapsAssetsDir, protocol)
286286

287287
const styles = await this.generateStylesFile(
288288
rawStyles,
@@ -342,9 +342,9 @@ export class MapService implements IMapService {
342342
return await listDirectoryContentsRecursive(this.baseDirPath)
343343
}
344344

345-
private generateSourcesArray(host: string | null, regions: FileEntry[]): BaseStylesFile['sources'][] {
345+
private generateSourcesArray(host: string | null, regions: FileEntry[], protocol: string = 'http'): BaseStylesFile['sources'][] {
346346
const sources: BaseStylesFile['sources'][] = []
347-
const baseUrl = this.getPublicFileBaseUrl(host, 'pmtiles')
347+
const baseUrl = this.getPublicFileBaseUrl(host, 'pmtiles', protocol)
348348

349349
for (const region of regions) {
350350
if (region.type === 'file' && region.name.endsWith('.pmtiles')) {
@@ -433,7 +433,7 @@ export class MapService implements IMapService {
433433
/*
434434
* Gets the appropriate public URL for a map asset depending on environment
435435
*/
436-
private getPublicFileBaseUrl(specifiedHost: string | null, childPath: string): string {
436+
private getPublicFileBaseUrl(specifiedHost: string | null, childPath: string, protocol: string = 'http'): string {
437437
function getHost() {
438438
try {
439439
const localUrlRaw = env.get('URL')
@@ -447,7 +447,7 @@ export class MapService implements IMapService {
447447
}
448448

449449
const host = specifiedHost || getHost()
450-
const withProtocol = host.startsWith('http') ? host : `http://${host}`
450+
const withProtocol = host.startsWith('http') ? host : `${protocol}://${host}`
451451
const baseUrlPath =
452452
process.env.NODE_ENV === 'production' ? childPath : urlJoin(this.mapStoragePath, childPath)
453453

admin/inertia/components/maps/MapComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function MapComponent() {
2323
width: '100%',
2424
height: '100vh',
2525
}}
26-
mapStyle={`http://${window.location.hostname}:${window.location.port}/api/maps/styles`}
26+
mapStyle={`${window.location.protocol}//${window.location.hostname}:${window.location.port}/api/maps/styles`}
2727
mapLib={maplibregl}
2828
initialViewState={{
2929
longitude: -101,

0 commit comments

Comments
 (0)