diff --git a/.env.example b/.env.example index f00f4473..5bc96d6d 100644 --- a/.env.example +++ b/.env.example @@ -37,13 +37,22 @@ MOBILE_APP_ANDROID_PACKAGE=life.doxa.pray # Mapbox (used by the prayer map on /pray) NUXT_PUBLIC_MAPBOX_TOKEN=your-mapbox-public-token -# Research page: where the dx-maps tree loads from. Unset = the maps CDN below (this branch's default). -# Set it empty (NUXT_PUBLIC_DX_MAPS_BASE=) to use this site's own public/dx-maps copy instead. -# The CDN must send Access-Control-Allow-Origin for the tree. -# NUXT_PUBLIC_DX_MAPS_BASE=https://maps-dev.nuxtbase.app/cdn/dx-maps - -# The Research Gallery's subdomain (the hamburger menu's Research item links here). -# NUXT_PUBLIC_RESEARCH_GALLERY_URL=https://research.nuxtbase.app +# The plugin-studio branch's two addresses, per deployment. Both are REQUIRED, and both are read by the +# server at REQUEST time (server/utils/dx-runtime.ts). They are never baked into a build, so one build +# serves any deployment. Changing them needs a restart, not a rebuild. There is no default host: when +# one is unset, the pages that need it say which setting is missing. +# +# The Research Gallery: the public Plugin Studio on its own subdomain. The menu's Research item, every +# in-page gallery link and the /regions index go here (through this site's /research-gallery). +# VPS: NUXT_PUBLIC_RESEARCH_GALLERY_URL=https://research./ +# laptop: NUXT_PUBLIC_RESEARCH_GALLERY_URL=http://research.localhost:4616/ +NUXT_PUBLIC_RESEARCH_GALLERY_URL= +# +# The dx-maps tree this site's maps load from: that subdomain's published /cdn. It must send +# Access-Control-Allow-Origin for the tree (the container does). +# VPS: NUXT_PUBLIC_DX_MAPS_BASE=https://research./cdn/dx-maps +# laptop: NUXT_PUBLIC_DX_MAPS_BASE=http://research.localhost:4616/cdn/dx-maps +NUXT_PUBLIC_DX_MAPS_BASE= # Cloudflare Turnstile NUXT_TURNSTILE_SITE_KEY=your-turnstile-site-key diff --git a/DX-MAPS-GALLERY.md b/DX-MAPS-GALLERY.md index 4da4134f..0684a928 100644 --- a/DX-MAPS-GALLERY.md +++ b/DX-MAPS-GALLERY.md @@ -54,14 +54,36 @@ or `.env` is needed for this page. Without `DATABASE_URL`, the dev server only l - To run it against a **local** dx-maps, and to try all three ways a site can take the gallery (drop-in, CDN, subdomain) with the exact ports and settings: [documentation/LAPTOP-6WAY.md](documentation/LAPTOP-6WAY.md). -## Deployment method: the Research Gallery on its own subdomain (this branch, research-gallery-subdomain) +## Deployment method: the Research Gallery as the public Plugin Studio (this branch, research-gallery-plugin-studio) -The hamburger menu's **Research** item links to the Research Gallery on its own subdomain, served by the -Plugin Studio container: `NUXT_PUBLIC_RESEARCH_GALLERY_URL`, default `https://research.nuxtbase.app`. The -menu no longer lists this site's Research page or its **Regions** page (the Regions item is switched off -with `off: true` in `app/utils/nav.ts`, not deleted; both pages still exist at `/research` and `/regions`, -and in-page links to them, such as the home map's research button, are unchanged). The site's other maps -and `/embed-test` load as JavaScript from the maps CDN, as on research-gallery-js. No iframe is used. +The research subdomain runs the dx-maps container in its public mode: the **Plugin Studio**, open to +everyone, with every research map, dashboard and list, and its published `/cdn` of production maps. +This site sends readers there and loads its own maps from there. Each deployment sets two addresses, +read by the server at **request time** and never baked into a build: + +| Setting | What it is | VPS | Laptop | +|---|---|---|---| +| `NUXT_PUBLIC_RESEARCH_GALLERY_URL` | the public Plugin Studio | `https://research./` | `http://research.localhost:4616/` | +| `NUXT_PUBLIC_DX_MAPS_BASE` | its published tree, where this site's maps load from | `https://research./cdn/dx-maps` | `http://research.localhost:4616/cdn/dx-maps` | + +**Why request time.** About 4,000 pages are prerendered, and a prerendered page carries the build's +runtime config. An address read there would be baked into the build, which is how the CDN branch +failed. So neither setting is in `nuxt.config.ts`: +- **Links:** the menu's **Research** item, every in-page gallery link and the `/regions` and + `/countries` index pages go to this site's own `/research-gallery?tab=…&lang=…`. The server + redirects that (302) to the deployment's gallery (`server/routes/research-gallery.get.ts`). +- **Maps:** every map (the home, pray and adopt maps, `/embed-test`, `/research`, and the static pages + under `public/`) first asks this site's server for the tree (`GET /api/dx-runtime`), then loads its + bundle from there. +- **Old links:** old `/js/doxa-maps/…` links are redirected per request to the same path in the tree + (`server/middleware/legacy-map-links.ts`). + +When a setting is unset there is no fallback host. `/research-gallery` answers 503 and the maps say +which setting to set. Changing an address needs a restart, not a rebuild. + +The menu no longer lists this site's Research page or its **Regions** page. The Regions item is +switched off with `off: true` in `app/utils/nav.ts`, not deleted. `/research` is kept, unlinked, and +the region and country detail pages stay. No iframe is used. ## /embed-test diff --git a/app/components/DoxaMapSlot.vue b/app/components/DoxaMapSlot.vue index d77e6692..9d41f6bc 100644 --- a/app/components/DoxaMapSlot.vue +++ b/app/components/DoxaMapSlot.vue @@ -11,7 +11,8 @@ interface Props { const props = withDefaults(defineProps(), { bundle: 'simple-map' }) -useDoxaMap(props.bundle) +// base: the deployment's dx-maps tree, known once this site's server answers (''); error: why not, in words. +const { base, error } = useDoxaMap(props.bundle) /* Each bundle registers a DIFFERENT custom element name so both IIFEs can * coexist on the same SPA. customElements.define() is one-shot per tag, @@ -35,16 +36,16 @@ onMounted(() => { * dx-maps bundle for its keyless MapLibre engine instead, as the Research * page does. With a token, the config passes through unchanged. */ /* The map's own files (styles, boundaries) live in the dx-maps tree it was loaded from, not on this - * site: without assetsBase the bundle would look for them under this page's ./assets. */ + * site: without assetsBase the bundle would look for them under this page's ./assets. The tree's + * address comes from the server at runtime (useDoxaMap), so the element is added only once it is known. */ const runtimeConfig = useRuntimeConfig() -const dxMapsBase = ((runtimeConfig.public as { dxMapsBase?: string }).dxMapsBase || '').replace(/\/+$/, '') || '/dx-maps' /* The site's language (it lives in the URL path, /ar/pray, which the map cannot read) goes to the map as * its locale, so its text, direction and data follow DX-life's language and its switcher. */ const { locale } = useI18n() const effectiveConfig = computed(() => { try { // The page's own tk is ignored: the site's provider setting decides (MapLibre by default). - const { tk: _pageToken, ...cfg } = { assetsBase: `${dxMapsBase}/assets`, locale: locale.value, ...JSON.parse(props.profileConfig) } + const { tk: _pageToken, ...cfg } = { assetsBase: `${base.value}/assets`, locale: locale.value, ...JSON.parse(props.profileConfig) } const tk = mapboxTokenIfChosen(runtimeConfig.public) return JSON.stringify(tk ? { ...cfg, tk } : { ...cfg, provider: 'maplibre' }) } catch { @@ -55,14 +56,24 @@ const effectiveConfig = computed(() => {