Powered by

diff --git a/src/runtimeConfig.ts b/src/runtimeConfig.ts
new file mode 100644
index 0000000..efd96aa
--- /dev/null
+++ b/src/runtimeConfig.ts
@@ -0,0 +1,36 @@
+// Runtime configuration, per frontgen's placement contract.
+//
+// A deployed artifact carries no environment values. When frontgen places a
+// build it writes config.js next to index.html and rewrites the
+// placeholder into a real
. That is what lets one
+// artifact serve any mount path — /p2p/ here, something else after promotion —
+// without being rebuilt. See sm2/frontgen internal/deploy/place.go and the
+// checks in internal/builder/assert.go.
+
+declare global {
+ interface Window {
+ __RUNTIME_CONFIG__?: Record
;
+ }
+}
+
+// SAME_ORIGIN is what placement writes for a custom-domain mount, where the
+// platform is proxied under the serving host. An empty string could not express
+// it — it is falsy, so it would fall through the || chain below.
+export function resolveConfigValue(key: string, fallback = ""): string {
+ const runtime = (window.__RUNTIME_CONFIG__ || {})[key];
+ const devFallback = import.meta.env.DEV ? (import.meta.env[key] as string) : "";
+ const value = runtime || devFallback || fallback;
+ return value === "SAME_ORIGIN" ? window.location.origin.replace(/\/$/, "") : value;
+}
+
+// The mount path this app is served under, read from the placement
+// writes. Drives the router basename and every public-asset URL.
+//
+// The guard is for `npm run dev`, where the placeholder is still an HTML
+// comment: without it document.baseURI is just the current page URL, so a deep
+// link like /invoices/12 would yield "/invoices/12" as the basename and the
+// router would match nothing.
+export function basePath(): string {
+ if (!document.querySelector("base")) return "/";
+ return new URL(document.baseURI).pathname;
+}
diff --git a/vite.config.ts b/vite.config.ts
index ab7e91f..248462c 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -11,7 +11,10 @@ export default defineConfig({
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
},
- base: process.env.VITE_BASE_URL ?? '/p2p/',
+ // Relative, never a mount path: frontgen's placement step writes the real
+ // into index.html, so one artifact serves any mount without a
+ // rebuild. An absolute base fails internal/builder/assert.go.
+ base: './',
server: {
port: 3007,
proxy: {