mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 03:29:25 +01:00
fix(Maps): static path resolution
This commit is contained in:
parent
d5db024eee
commit
f49b9abb81
|
|
@ -238,10 +238,7 @@ export class MapService implements IMapService {
|
|||
const regions = (await this.listRegions()).files
|
||||
const sources = this.generateSourcesArray(regions)
|
||||
|
||||
const localUrl = env.get('URL')
|
||||
const withProtocol = localUrl.startsWith('http') ? localUrl : `http://${localUrl}`
|
||||
const baseUrlPath = urlJoin(this.mapStoragePath, this.basemapsAssetsDir)
|
||||
const baseUrl = new URL(baseUrlPath, withProtocol).toString()
|
||||
const baseUrl = this.getPublicFileBaseUrl(this.basemapsAssetsDir)
|
||||
|
||||
const styles = await this.generateStylesFile(
|
||||
rawStyles,
|
||||
|
|
@ -317,17 +314,14 @@ export class MapService implements IMapService {
|
|||
}
|
||||
|
||||
private generateSourcesArray(regions: FileEntry[]): BaseStylesFile['sources'][] {
|
||||
const localUrl = env.get('URL')
|
||||
const sources: BaseStylesFile['sources'][] = []
|
||||
const baseUrl = this.getPublicFileBaseUrl('pmtiles')
|
||||
|
||||
for (const region of regions) {
|
||||
if (region.type === 'file' && region.name.endsWith('.pmtiles')) {
|
||||
const regionName = region.name.replace('.pmtiles', '')
|
||||
const source: BaseStylesFile['sources'] = {}
|
||||
const sourceUrl = new URL(
|
||||
urlJoin(this.mapStoragePath, 'pmtiles', region.name),
|
||||
localUrl.startsWith('http') ? localUrl : `http://${localUrl}`
|
||||
).toString()
|
||||
const sourceUrl = urlJoin(baseUrl, region.name)
|
||||
|
||||
source[regionName] = {
|
||||
type: 'vector',
|
||||
|
|
@ -388,4 +382,29 @@ export class MapService implements IMapService {
|
|||
|
||||
await deleteFileIfExists(fullPath)
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the appropriate public URL for a map asset depending on environment
|
||||
*/
|
||||
private getPublicFileBaseUrl(childPath: string): string {
|
||||
function getHost() {
|
||||
try {
|
||||
const localUrlRaw = env.get('URL')
|
||||
if (!localUrlRaw) return 'localhost'
|
||||
|
||||
const localUrl = new URL(localUrlRaw)
|
||||
return localUrl.host
|
||||
} catch (error) {
|
||||
return 'localhost'
|
||||
}
|
||||
}
|
||||
|
||||
const host = getHost()
|
||||
const withProtocol = host.startsWith('http') ? host : `http://${host}`
|
||||
const baseUrlPath =
|
||||
process.env.NODE_ENV === 'production' ? childPath : urlJoin(this.mapStoragePath, childPath)
|
||||
|
||||
const baseUrl = new URL(baseUrlPath, withProtocol).toString()
|
||||
return baseUrl
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export default class MapStaticProvider {
|
|||
register() {
|
||||
this.app.container.singleton(MapsStaticMiddleware, () => {
|
||||
const path = join(process.cwd(), '/storage/maps')
|
||||
logger.debug(`Maps static files will be served from ${path}`)
|
||||
logger.info(`Maps static files will be served from ${path}`)
|
||||
const config = this.app.config.get<any>('static', defineConfig({}))
|
||||
return new MapsStaticMiddleware(path, config)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ transmit.registerRoutes()
|
|||
router.get('/', [HomeController, 'index'])
|
||||
router.get('/home', [HomeController, 'home'])
|
||||
router.on('/about').renderInertia('about')
|
||||
router.get('/maps', [MapsController, 'index'])
|
||||
|
||||
router.get('/easy-setup', [EasySetupController, 'index'])
|
||||
router.get('/easy-setup/complete', [EasySetupController, 'complete'])
|
||||
|
|
@ -55,8 +56,6 @@ router
|
|||
})
|
||||
.prefix('/docs')
|
||||
|
||||
router.get('/maps', [MapsController, 'index'])
|
||||
|
||||
router
|
||||
.group(() => {
|
||||
router.get('/regions', [MapsController, 'listRegions'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user