doxa-maps-cdn/app/utils/dxRuntime.ts
doxa-maps 9e6e9a4bff Plugin Studio branch: lint the new code to the site's style
The map slot's template puts one attribute per line. The runtime loader and the
map composable put one statement per line. The origins check drops a redundant
pair of parentheses. No behaviour changes. Every file this branch touched now
has no more lint findings than it had before.
2026-09-29 05:12:51 +00:00

32 lines
1.2 KiB
TypeScript

// This deployment's Research Gallery and dx-maps tree, asked from this site's own server at RUNTIME
// (/api/dx-runtime). Never read from useRuntimeConfig(): about 4,000 pages are prerendered, and a
// prerendered page carries the build's values, so one build could not serve two deployments. See
// server/utils/dx-runtime.ts. Browser only: call it from onMounted or later. One request per page load.
export interface DxRuntime {
researchGalleryUrl: string
dxMapsBase: string
}
let pending: Promise<DxRuntime> | null = null
export function loadDxRuntime(): Promise<DxRuntime> {
if (!pending) {
pending = fetch('/api/dx-runtime', { cache: 'no-store' })
.then((r) => {
if (!r.ok) throw new Error(`/api/dx-runtime answered ${r.status}`)
return r.json() as Promise<DxRuntime>
})
.catch((e) => {
pending = null
throw e
})
}
return pending
}
// The dx-maps tree's address, or an Error that names the missing setting.
export async function dxMapsBaseOrThrow(): Promise<string> {
const { dxMapsBase } = await loadDxRuntime()
if (!dxMapsBase) throw new Error('This deployment has no maps address: set NUXT_PUBLIC_DX_MAPS_BASE.')
return dxMapsBase
}