- allow the vite dev server origins in development and the compose port origins in production; CORS_ORIGINS overrides both - set NODE_ENV=production in the runtime docker image - document both settings in .env.example and the development docs - bump version to 1.19.3
24 lines
959 B
TypeScript
24 lines
959 B
TypeScript
/** Vite dev server (`npm -w client run dev`), calling the API cross-origin. */
|
|
const DEV_ORIGINS = ["http://localhost:5173", "http://127.0.0.1:5173"];
|
|
|
|
/**
|
|
* The port compose.yaml publishes. The UI is served from the same origin in
|
|
* production, so these only matter for other tools calling the API from a
|
|
* page on that origin; keep in sync with compose.yaml.
|
|
*/
|
|
const PRODUCTION_ORIGINS = ["http://localhost:13000", "http://127.0.0.1:13000"];
|
|
|
|
/**
|
|
* Origins allowed to call the API cross-origin. `CORS_ORIGINS` (comma
|
|
* separated) overrides the defaults, which depend on NODE_ENV: the compose
|
|
* port in production, the Vite dev server otherwise.
|
|
*/
|
|
export function corsOrigins(nodeEnv: string, override: string): string[] {
|
|
const configured = override
|
|
.split(",")
|
|
.map((origin) => origin.trim())
|
|
.filter(Boolean);
|
|
if (configured.length > 0) return configured;
|
|
return nodeEnv === "production" ? PRODUCTION_ORIGINS : DEV_ORIGINS;
|
|
}
|