doxa-maps-cdn/server/utils/dx-runtime.ts
doxa-maps ba1a906168 Plugin Studio branch: the gallery and maps addresses are read per request, never baked
This branch sends readers to the Research Gallery (the public Plugin Studio
on its own subdomain) and loads the site's maps from that subdomain's /cdn.
Both addresses belong to the deployment:
  NUXT_PUBLIC_RESEARCH_GALLERY_URL  https://research.<host>/
  NUXT_PUBLIC_DX_MAPS_BASE          https://research.<host>/cdn/dx-maps

About 4,000 pages are prerendered, and a prerendered page carries the
build's runtime config, so an address read there is baked into the build.
One build could then serve only one deployment; the CDN branch failed that
way. So neither address is in nuxt.config any more:
- the server reads both from its environment per request
  (server/utils/dx-runtime.ts);
- GET /api/dx-runtime answers them, no-store. Every map (DoxaMapSlot via
  useDoxaMap, /research, /embed-test, and the static pages under public/)
  asks it first, then loads its bundle from that tree. The map's element is
  added only once the tree is known, and the map bundle's preload is added
  then, still while Mapbox downloads;
- every gallery link, the Research menu item, and the /regions and
  /countries index rules go to this site's /research-gallery?tab=&lang=,
  which 302s (no-store) to the gallery. It works without JavaScript, and a
  prerendered page names no host;
- old /js/doxa-maps and /embed/doxa-maps-build links are redirected per
  request by server/middleware/legacy-map-links.ts. They were build-time
  route rules.

No fallback host: the maps-dev and research defaults are gone. When a
setting is unset, /research-gallery answers 503 and each map says which
setting to set. Changing an address needs a restart, not a rebuild.
2026-09-29 04:48:59 +00:00

30 lines
1.5 KiB
TypeScript

/**
* The two per-deployment addresses of the plugin-studio branch, read from the server's environment
* at REQUEST time:
*
* NUXT_PUBLIC_RESEARCH_GALLERY_URL the Research Gallery: the public Plugin Studio on its own
* subdomain (https://research.<host>/). The Research menu item,
* every in-page gallery link and the /regions index go there.
* NUXT_PUBLIC_DX_MAPS_BASE the dx-maps tree this site's maps load from: that subdomain's
* published /cdn (https://research.<host>/cdn/dx-maps).
*
* Why not runtimeConfig.public: about 4,000 pages are PRERENDERED at build time, and a prerendered
* page carries the build's runtime config in its payload. An address read there is baked into the
* build, and one build could not serve two deployments. The CDN branch died of exactly that. So
* neither value is declared in nuxt.config, neither is ever in a page, and the client asks this
* server for them (/api/dx-runtime), the way the static pages already ask for the map token
* (/api/maps/token). Unset means unset: there is no fallback host, and every caller says which
* setting is missing.
*/
export interface DxRuntime {
researchGalleryUrl: string
dxMapsBase: string
}
export function dxRuntime(): DxRuntime {
const read = (name: string) => String(process.env[name] || '').trim()
return {
researchGalleryUrl: read('NUXT_PUBLIC_RESEARCH_GALLERY_URL'),
dxMapsBase: read('NUXT_PUBLIC_DX_MAPS_BASE').replace(/\/+$/, '')
}
}