From 2ee2adf0486622b3a52aedaf511b91cc46723813 Mon Sep 17 00:00:00 2001 From: BigBodyCobain <43977454+BigBodyCobain@users.noreply.github.com> Date: Mon, 23 Nov 2026 09:57:25 -0700 Subject: [PATCH] Viewer: publish under a sub-folder, data from another static host Co-Authored-By: Claude Fable 5.2 --- viewer/README.md | 19 +++++++++++++++++++ viewer/web/build.mjs | 12 ++++++++++++ viewer/web/cuts.json | 12 ++++++++++++ viewer/web/overlay/next.config.ts | 4 ++++ viewer/web/overlay/src/app/page.tsx | 4 ++-- viewer/web/overlay/src/viewer/SkillModal.tsx | 4 ++-- .../web/overlay/src/viewer/ViewerChrome.tsx | 4 ++-- viewer/web/overlay/src/viewer/config.ts | 14 +++++++++++++- 8 files changed, 66 insertions(+), 7 deletions(-) diff --git a/viewer/README.md b/viewer/README.md index e0f2438e..1bcb0c88 100644 --- a/viewer/README.md +++ b/viewer/README.md @@ -98,6 +98,25 @@ Some layers show a location and hand the visitor to the source's own site: In every case the viewer supplies an address and nothing else. +## Publishing under another site, with no server of your own + +The viewer can live in a sub-folder of an existing static site, and the data +files can come from a different static host: + +```bash +NEXT_PUBLIC_SB_BASE_PATH=/map NEXT_PUBLIC_SB_DATA_BASE=https:/// NEXT_PUBLIC_SB_STALE_AFTER_S=900 node viewer/web/build.mjs +``` + +Copy `viewer/web/dist/` into the site's `map/` folder. `NEXT_PUBLIC_SB_STALE_AFTER_S` +is how old the data may get before the page says so; set it to a few times +the interval at which the data files are replaced. + +The engine and bridge only need to run somewhere that can make outbound +requests. Nothing has to accept a connection from the internet: a scheduled +job on a hosted build runner can run them and publish the bridge's output +folder to a static host. Only the files named in `manifest.json` should be +published. + ## The agent skill can be read before it is used The site has an "AI agent skill" button. It shows every file of diff --git a/viewer/web/build.mjs b/viewer/web/build.mjs index 758f8b0e..de4ff7e5 100644 --- a/viewer/web/build.mjs +++ b/viewer/web/build.mjs @@ -18,6 +18,8 @@ * Usage: * node viewer/web/build.mjs # build + checks * NEXT_PUBLIC_SB_DATA_BASE=https://data.example.org node viewer/web/build.mjs + * NEXT_PUBLIC_SB_BASE_PATH=/map ... publish under a sub-folder of another site + * NEXT_PUBLIC_SB_STALE_AFTER_S=1500 ... data older than this is shown as stale (default 240) * node viewer/web/build.mjs --prepare-only # stop after step 3 */ @@ -278,6 +280,8 @@ const env = { // so only the names below get through. const PUBLIC_SETTINGS = new Set([ 'NEXT_PUBLIC_SB_DATA_BASE', + 'NEXT_PUBLIC_SB_BASE_PATH', + 'NEXT_PUBLIC_SB_STALE_AFTER_S', 'NEXT_PUBLIC_SB_CHAT_URL', 'NEXT_PUBLIC_SB_CHAT_KEY', 'NEXT_PUBLIC_SB_CHAT_PROVIDERS', @@ -286,6 +290,14 @@ for (const name of Object.keys(env)) { if (name.startsWith('NEXT_PUBLIC_') && !PUBLIC_SETTINGS.has(name)) delete env[name]; } +// Publishing in a sub-folder ("/map"): lower-case folder names only, no trailing slash. +if (env.NEXT_PUBLIC_SB_BASE_PATH && !/^(\/[a-z0-9][a-z0-9-]*)+$/.test(env.NEXT_PUBLIC_SB_BASE_PATH)) { + fail(`NEXT_PUBLIC_SB_BASE_PATH must look like /map, got "${env.NEXT_PUBLIC_SB_BASE_PATH}"`); +} +if (env.NEXT_PUBLIC_SB_STALE_AFTER_S && !/^[1-9][0-9]{1,5}$/.test(env.NEXT_PUBLIC_SB_STALE_AFTER_S)) { + fail(`NEXT_PUBLIC_SB_STALE_AFTER_S must be a number of seconds, got "${env.NEXT_PUBLIC_SB_STALE_AFTER_S}"`); +} + // Optional chat settings from viewer/web/chat.config.json (see viewer/chat/README.md). const chatConfigPath = path.join(here, 'chat.config.json'); if (fs.existsSync(chatConfigPath)) { diff --git a/viewer/web/cuts.json b/viewer/web/cuts.json index 3225eadd..6caa2f5c 100644 --- a/viewer/web/cuts.json +++ b/viewer/web/cuts.json @@ -72,6 +72,18 @@ "file": "src/components/MaplibreViewer.tsx", "find": " OPEN PLAYER", "replace": " LISTEN ON OPENMHZ ↗" + }, + { + "why": "sub-folder hosting: the map worker file sits next to the viewer, not at the top of the site", + "file": "src/components/MaplibreViewer.tsx", + "find": "maplibregl.setWorkerUrl('/maplibre-gl-worker.mjs');", + "replace": "maplibregl.setWorkerUrl(`${process.env.NEXT_PUBLIC_SB_BASE_PATH || ''}/maplibre-gl-worker.mjs`);" + }, + { + "why": "sub-folder hosting: the cable map file sits next to the viewer, not at the top of the site", + "file": "src/components/MaplibreViewer.tsx", + "find": "fetch('/data/submarine-cables.json')", + "replace": "fetch(`${process.env.NEXT_PUBLIC_SB_BASE_PATH || ''}/data/submarine-cables.json`)" } ] } diff --git a/viewer/web/overlay/next.config.ts b/viewer/web/overlay/next.config.ts index 103dc506..c52f3d6f 100644 --- a/viewer/web/overlay/next.config.ts +++ b/viewer/web/overlay/next.config.ts @@ -1,7 +1,11 @@ import type { NextConfig } from 'next'; // Public viewer build: a plain static site. No server, no API routes, no proxy. +// Set when the site is published in a sub-folder of another site, e.g. "/map". +const basePath = process.env.NEXT_PUBLIC_SB_BASE_PATH || ''; + const nextConfig: NextConfig = { + ...(basePath ? { basePath } : {}), transpilePackages: ['react-map-gl'], output: 'export', devIndicators: false, diff --git a/viewer/web/overlay/src/app/page.tsx b/viewer/web/overlay/src/app/page.tsx index d400e794..f1038fde 100644 --- a/viewer/web/overlay/src/app/page.tsx +++ b/viewer/web/overlay/src/app/page.tsx @@ -37,7 +37,7 @@ import { useAlertToasts } from '@/hooks/useAlertToasts'; import { useWatchlist } from '@/hooks/useWatchlist'; import { useTranslation } from '@/i18n'; import { LocateBar } from './LocateBar'; -import { VIEWER_HIDDEN_LAYERS } from '@/viewer/config'; +import { VIEWER_HIDDEN_LAYERS, asset } from '@/viewer/config'; import { layersOnLoad, layersToStore, readLayerRev, withHiddenOff, writeLayerRev } from '@/viewer/layerPrefs'; import { AboutModal, StaleBanner, ViewerHeaderCard, ViewerToolsPanel } from '@/viewer/ViewerChrome'; import SkillModal from '@/viewer/SkillModal'; @@ -349,7 +349,7 @@ export default function ViewerDashboard() { className="absolute top-6 left-6 z-[200] pointer-events-none flex items-center gap-4 hud-zone" > {/* eslint-disable-next-line @next/next/no-img-element */} - +

SHADOWBROKER diff --git a/viewer/web/overlay/src/viewer/SkillModal.tsx b/viewer/web/overlay/src/viewer/SkillModal.tsx index e0f1268d..5b5ca186 100644 --- a/viewer/web/overlay/src/viewer/SkillModal.tsx +++ b/viewer/web/overlay/src/viewer/SkillModal.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react'; import { Bot, Check, Copy, Download, ShieldCheck, X } from 'lucide-react'; -import { VIEWER_DATA_BASE } from './config'; +import { VIEWER_DATA_BASE, asset } from './config'; /** * "View and vet" screen for the public agent skill. @@ -22,7 +22,7 @@ type SkillManifest = { files: SkillFile[]; }; -const SKILL_BASE = '/skill'; +const SKILL_BASE = asset('/skill'); const FACTS: { good: boolean; text: string }[] = [ { good: true, text: 'Reads the same public data files this page uses.' }, diff --git a/viewer/web/overlay/src/viewer/ViewerChrome.tsx b/viewer/web/overlay/src/viewer/ViewerChrome.tsx index eec3f9da..7b560a52 100644 --- a/viewer/web/overlay/src/viewer/ViewerChrome.tsx +++ b/viewer/web/overlay/src/viewer/ViewerChrome.tsx @@ -279,8 +279,8 @@ export function AboutModal({ onClose }: { onClose: () => void }) {

- This is a look-only window onto ShadowBroker. It shows a copy of public map data that refreshes a few - times a minute. You can pan, zoom, filter and switch layers; those choices stay in your browser. + This is a look-only window onto ShadowBroker. It shows a copy of public map data that refreshes every + few minutes. You can pan, zoom, filter and switch layers; those choices stay in your browser.

Nothing here can send a message, post, change a setting or start a scan. This page has no connection to diff --git a/viewer/web/overlay/src/viewer/config.ts b/viewer/web/overlay/src/viewer/config.ts index 184077c5..58e1f0ac 100644 --- a/viewer/web/overlay/src/viewer/config.ts +++ b/viewer/web/overlay/src/viewer/config.ts @@ -3,6 +3,17 @@ * key, token or private address in the viewer build. */ +/** + * The folder the viewer itself is published in ("" at the top of a site, + * "/map" under another site). Set at build time. + */ +export const VIEWER_BASE_PATH = (process.env.NEXT_PUBLIC_SB_BASE_PATH || '').replace(/\/+$/, ''); + +/** Address of one of the viewer's own static files, e.g. asset('/skill/manifest.json'). */ +export function asset(path: string): string { + return `${VIEWER_BASE_PATH}${path}`; +} + /** Where the bridge's files are served from. Set at build time. */ export const VIEWER_DATA_BASE = (process.env.NEXT_PUBLIC_SB_DATA_BASE || '/live-data').replace(/\/+$/, ''); @@ -32,7 +43,8 @@ export const VIEWER_HIDDEN_LAYERS: ReadonlySet = new Set([ ]); /** Data older than this is shown as stale instead of live. */ -export const VIEWER_STALE_AFTER_MS = 4 * 60 * 1000; +export const VIEWER_STALE_AFTER_MS = + (Number(process.env.NEXT_PUBLIC_SB_STALE_AFTER_S) > 0 ? Number(process.env.NEXT_PUBLIC_SB_STALE_AFTER_S) : 240) * 1000; export const VIEWER_REPO_URL = 'https://github.com/BigBodyCobain/Shadowbroker';