Add path-prefix deployment support for migrating to podsteadr's domain

Regress needs to live at podsteadr.atobitcoin.io/regress/ since / is
already podsteadr. Two coordinated pieces:
- VITE_BASE build arg (frontend asset/script paths, %BASE_URL% in
  index.html for the nostr-provider.js script tag)
- ROUTE_PREFIX runtime env (backend routes registered under the prefix
  via Fastify's plugin-encapsulation, including /api/health)

The nginx location must forward the prefix unstripped (proxy_pass with
no trailing path) — NIP-98 login signs the exact URL it calls, so a
stripped prefix makes the backend reconstruct a different URL than what
was signed and every login fails. Caught this with a real nginx+docker
integration test locally before it could break the live migration, then
fixed a matching bug in auth.ts (it was signing the unprefixed URL while
api.ts fetched the prefixed one). New routePrefix.test.ts proves the
prefix is actually enforced, including a negative case. 40 tests passing.

Also fixes a latent bug: import.meta.env usage had no vite/client type
reference, so it only ever passed typecheck by accident in earlier local
runs — added the standard vite-env.d.ts.
This commit is contained in:
2026-08-05 14:58:43 +00:00
parent df9a4ae74b
commit 517186ac55
11 changed files with 214 additions and 61 deletions
+7
View File
@@ -6,6 +6,13 @@ const envSchema = z.object({
DATA_DIR: z.string().default('./data'),
STATIC_DIR: z.string().optional(),
PUBLIC_URL: z.string().url().default('http://localhost:8096'),
// Set when this instance is deployed under a path prefix on a shared domain
// (e.g. "/regress" on podsteadr.atobitcoin.io/regress/) rather than at
// root. Must match nginx's location block, which must NOT strip the
// prefix — the NIP-98 `u` tag the frontend signs includes it, so the
// backend needs to see (and route) the same full path. Leave unset ("") to
// deploy at root, e.g. its own dedicated host/port.
ROUTE_PREFIX: z.string().default(''),
NIP98_MAX_SKEW_SECS: z.coerce.number().default(60),
SESSION_TTL_DAYS: z.coerce.number().default(30),
// Default sync area: Madeira, Portugal (Funchal-centered radius covering the whole island).