mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-03 15:26:16 +02:00
fix(maps): respect request protocol for reverse proxy HTTPS support
This commit is contained in:
parent
8bb8b414f8
commit
d0eeeb5052
|
|
@ -83,7 +83,7 @@ export default class MapsController {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = await this.mapService.generateStylesJSON(request.host())
|
const styles = await this.mapService.generateStylesJSON(request.host(), request.protocol())
|
||||||
return response.json(styles)
|
return response.json(styles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ export class MapService implements IMapService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateStylesJSON(host: string | null = null): Promise<BaseStylesFile> {
|
async generateStylesJSON(host: string | null = null, protocol: string = 'http'): Promise<BaseStylesFile> {
|
||||||
if (!(await this.checkBaseAssetsExist())) {
|
if (!(await this.checkBaseAssetsExist())) {
|
||||||
throw new Error('Base map assets are missing from storage/maps')
|
throw new Error('Base map assets are missing from storage/maps')
|
||||||
}
|
}
|
||||||
|
|
@ -281,8 +281,8 @@ export class MapService implements IMapService {
|
||||||
* e.g. user is accessing from "example.com", but we would by default generate "localhost:8080/..." so maps would
|
* e.g. user is accessing from "example.com", but we would by default generate "localhost:8080/..." so maps would
|
||||||
* fail to load.
|
* fail to load.
|
||||||
*/
|
*/
|
||||||
const sources = this.generateSourcesArray(host, regions)
|
const sources = this.generateSourcesArray(host, regions, protocol)
|
||||||
const baseUrl = this.getPublicFileBaseUrl(host, this.basemapsAssetsDir)
|
const baseUrl = this.getPublicFileBaseUrl(host, this.basemapsAssetsDir, protocol)
|
||||||
|
|
||||||
const styles = await this.generateStylesFile(
|
const styles = await this.generateStylesFile(
|
||||||
rawStyles,
|
rawStyles,
|
||||||
|
|
@ -342,9 +342,9 @@ export class MapService implements IMapService {
|
||||||
return await listDirectoryContentsRecursive(this.baseDirPath)
|
return await listDirectoryContentsRecursive(this.baseDirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateSourcesArray(host: string | null, regions: FileEntry[]): BaseStylesFile['sources'][] {
|
private generateSourcesArray(host: string | null, regions: FileEntry[], protocol: string = 'http'): BaseStylesFile['sources'][] {
|
||||||
const sources: BaseStylesFile['sources'][] = []
|
const sources: BaseStylesFile['sources'][] = []
|
||||||
const baseUrl = this.getPublicFileBaseUrl(host, 'pmtiles')
|
const baseUrl = this.getPublicFileBaseUrl(host, 'pmtiles', protocol)
|
||||||
|
|
||||||
for (const region of regions) {
|
for (const region of regions) {
|
||||||
if (region.type === 'file' && region.name.endsWith('.pmtiles')) {
|
if (region.type === 'file' && region.name.endsWith('.pmtiles')) {
|
||||||
|
|
@ -433,7 +433,7 @@ export class MapService implements IMapService {
|
||||||
/*
|
/*
|
||||||
* Gets the appropriate public URL for a map asset depending on environment
|
* Gets the appropriate public URL for a map asset depending on environment
|
||||||
*/
|
*/
|
||||||
private getPublicFileBaseUrl(specifiedHost: string | null, childPath: string): string {
|
private getPublicFileBaseUrl(specifiedHost: string | null, childPath: string, protocol: string = 'http'): string {
|
||||||
function getHost() {
|
function getHost() {
|
||||||
try {
|
try {
|
||||||
const localUrlRaw = env.get('URL')
|
const localUrlRaw = env.get('URL')
|
||||||
|
|
@ -447,7 +447,7 @@ export class MapService implements IMapService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const host = specifiedHost || getHost()
|
const host = specifiedHost || getHost()
|
||||||
const withProtocol = host.startsWith('http') ? host : `http://${host}`
|
const withProtocol = host.startsWith('http') ? host : `${protocol}://${host}`
|
||||||
const baseUrlPath =
|
const baseUrlPath =
|
||||||
process.env.NODE_ENV === 'production' ? childPath : urlJoin(this.mapStoragePath, childPath)
|
process.env.NODE_ENV === 'production' ? childPath : urlJoin(this.mapStoragePath, childPath)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export default function MapComponent() {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100vh',
|
height: '100vh',
|
||||||
}}
|
}}
|
||||||
mapStyle={`http://${window.location.hostname}:${window.location.port}/api/maps/styles`}
|
mapStyle={`${window.location.protocol}//${window.location.hostname}:${window.location.port}/api/maps/styles`}
|
||||||
mapLib={maplibregl}
|
mapLib={maplibregl}
|
||||||
initialViewState={{
|
initialViewState={{
|
||||||
longitude: -101,
|
longitude: -101,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user