Files
summercms/admin/src/app/runtime.ts
Jakub Zych 291b18fb1e feat(boardwalk): expose the admin build id and show a reload banner when a new build is deployed (quick-261028-rqb)
- boardwalk.BuildID hashes the dist tree plus the binary's build info once
  per handler; X-Summer-Build on every response, {prefix}/build.json and the
  summer-admin-build meta carry it
- the SPA reads the booted build, re-checks on focus, visibility and every
  5 minutes, and shows UpdateBanner on a different build
2026-10-28 21:19:36 +01:00

42 lines
1.6 KiB
TypeScript

// Runtime configuration read once from the served index.html. The Go server
// (boardwalk) writes the configured backend.uri into the summer-admin-base
// meta; the SPA derives its router base and API base from it (D-02, D-03).
// It also writes the build id into the summer-admin-build meta, the build the
// tab booted with (buildUpdate.ts compares it with build.json).
export const DEFAULT_BASE = '/backend'
const TOKEN = '__SUMMER_ADMIN_BASE__'
const BUILD_TOKEN = '__SUMMER_ADMIN_BUILD__'
const BUILD_SHAPE = /^[0-9a-f]{6,64}$/
export function readBase(doc: Document = document): string {
const content = doc.querySelector<HTMLMetaElement>('meta[name="summer-admin-base"]')?.content.trim() ?? ''
if (content === '' || content === TOKEN || !content.startsWith('/')) {
return DEFAULT_BASE
}
const trimmed = content.replace(/\/+$/, '')
return trimmed === '' ? DEFAULT_BASE : trimmed
}
/**
* The build id from the summer-admin-build meta, or "" when the meta is
* missing, empty, the unreplaced token (the dev server) or not lowercase hex.
*/
export function readBuild(doc: Document = document): string {
const content = doc.querySelector<HTMLMetaElement>('meta[name="summer-admin-build"]')?.content.trim() ?? ''
if (content === BUILD_TOKEN || !BUILD_SHAPE.test(content)) {
return ''
}
return content
}
const base = readBase()
export const runtime = {
/** Admin mount path, for example /backend. */
base,
/** Admin API root, the mount path plus /api/v1. */
api: `${base}/api/v1`,
/** The build id this tab booted with; "" turns the version check off. */
build: readBuild(),
} as const