feat(server): choose cors origins by NODE_ENV and run docker in production

- 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
This commit is contained in:
ars9 committed 2026-09-30 21:31:48 +03:00
1 parent a6d468bd2c
commit 5de9272281
11 files changed
+90 -6

No files matched your search

+6
View File
@@ -4,9 +4,15 @@
## Lines starting with "##" are descriptions. ## Lines starting with "##" are descriptions.
## Lines starting with "# " are settings: remove the "# " to enable one. ## Lines starting with "# " are settings: remove the "# " to enable one.
## production in the Docker image; also selects the default CORS origins
# NODE_ENV=development # NODE_ENV=development
# PORT=3000 # PORT=3000
## Origins allowed to call the API cross-origin (comma separated). Default: the
## Vite dev server (http://localhost:5173) in development, the compose port
## (http://localhost:13000) in production
# CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
## SQLite database path ## SQLite database path
# DB_PATH=data/liqa.db # DB_PATH=data/liqa.db
+14
View File
@@ -2,6 +2,20 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 1.19.3 - 2026-09-30
Changes since 1.19.2:
### Changed
- The Docker image runs with `NODE_ENV=production`.
- The origins allowed to call the API cross-origin depend on `NODE_ENV`: the Vite dev server (`http://localhost:5173`, `http://127.0.0.1:5173`) in development, the compose port (`http://localhost:13000`, `http://127.0.0.1:13000`) in production. The new `CORS_ORIGINS` setting (comma separated) overrides both. A `NODE_ENV=development` in `.env` overrides the image's production mode.
- `.env` is optional: compose loads it only when it exists, and every setting in `.env.example` is commented out and shows its default.
### Removed
- The unused `KEYS_DIR` setting and the `./keys` mount in `compose.yaml`.
## 1.19.2 - 2026-09-30 ## 1.19.2 - 2026-09-30
Changes since 1.19.1: Changes since 1.19.1:
+3
View File
@@ -31,6 +31,9 @@ RUN npm run -w server build
# ── Runtime ─────────────────────────────────────────────────────────────────── # ── Runtime ───────────────────────────────────────────────────────────────────
FROM node:24-slim AS runtime FROM node:24-slim AS runtime
# Runtime only: in the build stages it would make npm ci skip devDependencies
ENV NODE_ENV=production
# Shared libraries chrome-headless-shell links against (from `ldd`), plus # Shared libraries chrome-headless-shell links against (from `ldd`), plus
# fontconfig and basic fonts for text rendering. Playwright's `--with-deps` # fontconfig and basic fonts for text rendering. Playwright's `--with-deps`
# would also pull in xvfb (with Mesa/LLVM) and extra font packages, which # would also pull in xvfb (with Mesa/LLVM) and extra font packages, which
+3 -1
View File
@@ -3,7 +3,9 @@ services:
build: build:
context: . context: .
ports: ports:
# UI, REST API (/api/v1), MCP (/mcp) and Swagger (/docs) # UI, REST API (/api/v1), MCP (/mcp) and Swagger (/docs).
# The production CORS origins (server/src/common/cors.ts) use this port;
# set CORS_ORIGINS in .env when publishing it elsewhere.
- "13000:3000" - "13000:3000"
# Optional overrides (see .env.example); every setting has a default # Optional overrides (see .env.example); every setting has a default
env_file: env_file:
+2 -1
View File
@@ -27,7 +27,8 @@ All settings are validated at startup by `server/src/config/app.config.ts`.
| Variable | Default | Description | | Variable | Default | Description |
|---|---|---| |---|---|---|
| `NODE_ENV` | `development` | Shown in the startup log | | `NODE_ENV` | `development` | `production` in the Docker image. Shown in the startup log, and selects the default CORS origins |
| `CORS_ORIGINS` | *(empty)* | Comma-separated origins allowed to call the API cross-origin. When empty: the Vite dev server (`http://localhost:5173`, `http://127.0.0.1:5173`) unless `NODE_ENV=production`, then the compose port (`http://localhost:13000`, `http://127.0.0.1:13000`) |
| `PORT` | `3000` | HTTP port | | `PORT` | `3000` | HTTP port |
| `DB_PATH` | `data/liqa.db` | SQLite database file | | `DB_PATH` | `data/liqa.db` | SQLite database file |
| `FILES_DIR` | `data/files` | Where scenario files and run artifacts are stored | | `FILES_DIR` | `data/files` | Where scenario files and run artifacts are stored |
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "liqa", "name": "liqa",
"version": "1.19.2", "version": "1.19.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "liqa", "name": "liqa",
"version": "1.19.2", "version": "1.19.3",
"workspaces": [ "workspaces": [
"server", "server",
"client" "client"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "liqa", "name": "liqa",
"version": "1.19.2", "version": "1.19.3",
"private": true, "private": true,
"engines": { "engines": {
"node": ">=24" "node": ">=24"
+23
View File
@@ -0,0 +1,23 @@
/** 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;
}
+5
View File
@@ -17,9 +17,14 @@ export enum TraceMode {
} }
export class AppConfig { export class AppConfig {
/** `production` in the Docker image; also selects the default CORS origins. */
@IsString() @IsString()
NODE_ENV: string = "development"; NODE_ENV: string = "development";
/** Comma-separated origins allowed to call the API cross-origin; empty = default for NODE_ENV. */
@IsString()
CORS_ORIGINS: string = "";
@IsInt() @IsInt()
@Min(1) @Min(1)
@Max(65535) @Max(65535)
+2 -1
View File
@@ -6,6 +6,7 @@ import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { AppModule } from "./app.module"; import { AppModule } from "./app.module";
import { appPackage } from "./common/app-package"; import { appPackage } from "./common/app-package";
import { configureBodyParsers } from "./common/body-parsers"; import { configureBodyParsers } from "./common/body-parsers";
import { corsOrigins } from "./common/cors";
import { TraceLogger } from "./common/trace-logger"; import { TraceLogger } from "./common/trace-logger";
import { AppConfig } from "./config/app.config"; import { AppConfig } from "./config/app.config";
import { HttpExceptionFilter } from "./filters/http-exception.filter"; import { HttpExceptionFilter } from "./filters/http-exception.filter";
@@ -53,7 +54,7 @@ async function bootstrap() {
const nodeEnv = config.get("NODE_ENV"); const nodeEnv = config.get("NODE_ENV");
app.enableCors({ app.enableCors({
origin: ["http://localhost:5173", "http://127.0.0.1:5173"], origin: corsOrigins(nodeEnv, config.get("CORS_ORIGINS")),
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE", "OPTIONS"], methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE", "OPTIONS"],
credentials: true, credentials: true,
}); });
+29
View File
@@ -0,0 +1,29 @@
import { corsOrigins } from "../src/common/cors";
describe("corsOrigins", () => {
it("allows the Vite dev server outside production", () => {
for (const env of ["development", "test", ""]) {
expect(corsOrigins(env, "")).toEqual([
"http://localhost:5173",
"http://127.0.0.1:5173",
]);
}
});
it("allows the compose port in production", () => {
expect(corsOrigins("production", "")).toEqual([
"http://localhost:13000",
"http://127.0.0.1:13000",
]);
});
it("uses CORS_ORIGINS when set, in any environment", () => {
const override = " https://liqa.example.com , http://localhost:8080,";
for (const env of ["development", "production"]) {
expect(corsOrigins(env, override)).toEqual([
"https://liqa.example.com",
"http://localhost:8080",
]);
}
});
});