feat: support split Dashboard and API origins (ADR 0045)
CI / verify (pull_request) Successful in 49s
CI / infrastructure-smoke (pull_request) Successful in 13s
CI / migration-smoke (pull_request) Successful in 1m47s
CI / image-build (pull_request) Successful in 19s
CI / deploy-smoke (same-origin) (pull_request) Successful in 49s
CI / deploy-smoke (split) (pull_request) Successful in 1m4s
CI / verify (pull_request) Successful in 49s
CI / infrastructure-smoke (pull_request) Successful in 13s
CI / migration-smoke (pull_request) Successful in 1m47s
CI / image-build (pull_request) Successful in 19s
CI / deploy-smoke (same-origin) (pull_request) Successful in 49s
CI / deploy-smoke (split) (pull_request) Successful in 1m4s
An installation can now serve the Dashboard and the API on sibling hostnames (dash./api.) beside the default same-origin topology, from one image and with configuration alone. - The Dashboard learns its API origin at run time: the built page carries one empty <meta name="ekklesia-api-origin">, which the API fills with its identity base URL's origin at startup, before computing the page's ETag. The shell accepts only a canonical http(s) origin and otherwise fails closed without making a request. The build-time EKKLESIA_API_BASE_URL is gone from the bundle; the development server injects the same element. - The display host stays on the API's origin, so its device cookies, requests, and offline cache are unchanged. - The API trusts its own origin (trusted origins plus the identity base URL), as Better Auth already does, so the display page's mutations pass the origin check without operators listing it. - Doctor validates EKKLESIA_DASHBOARD_ORIGIN exactly as the API's startup does (it previously skipped it), reports the topology without printing hostnames, and warns when split hostnames are not siblings. - The module UI contract states the CORS header limit (safelisted headers plus Content-Type, safelisted response headers only). - Reference deployment: Caddyfile.split.example (Dashboard hostname serves / and its script; API hostname serves /api/*, /display/*, and the display script; each refuses the other's paths) and EKKLESIA_DASHBOARD_HOSTNAME in the proxy overlay and env examples. - The deploy smoke test runs either topology (CI runs both). The split run installs the module template as a test-only module, checks per-hostname routing and exact CORS, then drives a digest-pinned headless Chromium over the DevTools protocol, with no added dependency: sign-in on the Dashboard hostname, the session cookie host-only on the API hostname, the module UI imported cross-origin and its credentialed request succeeding, the display and its service worker on the API hostname, and sign-out. ADR 0045 is marked Accepted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
cbf5962d04
commit
f63f80f2f0
@@ -1,4 +1,4 @@
|
||||
import { copyFile, mkdir, rm } from "node:fs/promises";
|
||||
import { copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import esbuild from "esbuild";
|
||||
@@ -23,12 +23,16 @@ const outputDirectory = path.join(packageDirectory, "dist", "browser");
|
||||
const serve = process.argv.includes("--serve");
|
||||
|
||||
/**
|
||||
* Empty means "the API is on this page's own origin" — the expected production shape. Set it to an
|
||||
* absolute origin for split-origin development (`EKKLESIA_API_BASE_URL=http://127.0.0.1:3000`), and
|
||||
* add this page's own origin to `EKKLESIA_IDENTITY_TRUSTED_ORIGINS` so the API reflects it for CORS
|
||||
* and the session cookie travels.
|
||||
* Development only: the API origin the development server writes into its copy of the Dashboard page,
|
||||
* exactly as `apps/api` does at startup in production (ADR 0045). Empty means "the API is on this
|
||||
* page's own origin". Set it to an absolute origin for split-origin development
|
||||
* (`EKKLESIA_API_BASE_URL=http://127.0.0.1:3000`), and add this page's own origin to
|
||||
* `EKKLESIA_IDENTITY_TRUSTED_ORIGINS` so the API reflects it for CORS and the session cookie travels.
|
||||
* A production build never reads it: the built page always carries an empty value, and the bundle
|
||||
* carries no origin at all.
|
||||
*/
|
||||
const apiBaseUrl = process.env.EKKLESIA_API_BASE_URL ?? "";
|
||||
const apiBaseUrl = serve ? (process.env.EKKLESIA_API_BASE_URL ?? "") : "";
|
||||
const API_ORIGIN_PLACEHOLDER = '<meta content="" name="ekklesia-api-origin" />';
|
||||
|
||||
/** @type {import("esbuild").BuildOptions} */
|
||||
const buildOptions = {
|
||||
@@ -37,7 +41,6 @@ const buildOptions = {
|
||||
// artifacts it is told about, which are real URLs rather than bare specifiers.
|
||||
bundle: true,
|
||||
define: {
|
||||
__EKKLESIA_API_BASE_URL__: JSON.stringify(apiBaseUrl),
|
||||
// React reads this at module scope and a browser has no `process`.
|
||||
"process.env.NODE_ENV": JSON.stringify(serve ? "development" : "production"),
|
||||
},
|
||||
@@ -67,7 +70,17 @@ const buildOptions = {
|
||||
await rm(outputDirectory, { force: true, recursive: true });
|
||||
await mkdir(outputDirectory, { recursive: true });
|
||||
await mkdir(path.join(outputDirectory, "display"), { recursive: true });
|
||||
await copyFile(path.join(packageDirectory, "index.html"), path.join(outputDirectory, "index.html"));
|
||||
const dashboardPage = await readFile(path.join(packageDirectory, "index.html"), "utf8");
|
||||
if (dashboardPage.split(API_ORIGIN_PLACEHOLDER).length !== 2) {
|
||||
throw new Error("index.html must contain exactly one empty ekklesia-api-origin meta element.");
|
||||
}
|
||||
await writeFile(
|
||||
path.join(outputDirectory, "index.html"),
|
||||
dashboardPage.replace(
|
||||
API_ORIGIN_PLACEHOLDER,
|
||||
`<meta content="${apiBaseUrl.replaceAll("&", "&").replaceAll('"', """)}" name="ekklesia-api-origin" />`,
|
||||
),
|
||||
);
|
||||
await copyFile(
|
||||
path.join(packageDirectory, "display.html"),
|
||||
path.join(outputDirectory, "display", "index.html"),
|
||||
|
||||
Reference in New Issue
Block a user