mirror of
https://github.com/BigBodyCobain/Shadowbroker.git
synced 2026-12-05 00:53:37 +01:00
Viewer: publish under a sub-folder, data from another static host
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
39aae65897
commit
2ee2adf048
8 files changed
+66
-7
No files matched your search
@@ -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://<data host>/<folder> 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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -72,6 +72,18 @@
|
||||
"file": "src/components/MaplibreViewer.tsx",
|
||||
"find": "<Play size={10} /> OPEN PLAYER",
|
||||
"replace": "<Play size={10} /> 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`)"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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 */}
|
||||
<img src="/brand/sb-mark-72.webp" alt="" width={40} height={33} className="sb-brand-mark" />
|
||||
<img src={asset('/brand/sb-mark-72.webp')} alt="" width={40} height={33} className="sb-brand-mark" />
|
||||
<div className="flex flex-col">
|
||||
<h1 className="sb-wordmark" aria-label="ShadowBroker">
|
||||
SHADOW<span className="sb-wordmark-accent">BROKER</span>
|
||||
|
||||
@@ -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.' },
|
||||
|
||||
@@ -279,8 +279,8 @@ export function AboutModal({ onClose }: { onClose: () => void }) {
|
||||
</div>
|
||||
<div className="sb-prose mt-3 space-y-3 text-[13px] leading-relaxed text-[var(--text-primary)]">
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<p>
|
||||
Nothing here can send a message, post, change a setting or start a scan. This page has no connection to
|
||||
|
||||
@@ -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<string> = 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';
|
||||
|
||||
|
||||
Reference in new issue
Block a user