From a4bfa3117ff8c5bdabdaed0574179b961e9c1112 Mon Sep 17 00:00:00 2001 From: Andrii Arsenin Date: Wed, 30 Sep 2026 20:28:10 +0300 Subject: [PATCH] feat(docker): serve the whole app from a single container - serve the built client from the server via serve-static (CLIENT_DIR), falling back to index.html outside /api, /mcp, /docs and /health - replace server and client Dockerfiles and nginx with one root Dockerfile and a single liqa compose service on port 13000 - use Playwright's chromium-headless-shell with only its required libs and DejaVu/Liberation fonts instead of Debian chromium and Noto - clear the npm cache in the runtime image - bump version to 1.19.0 --- .dockerignore | 1 + .env.example | 7 +- CHANGELOG.md | 9 ++ CLAUDE.md | 10 +- Dockerfile | 87 ++++++++++++++++++ client/Dockerfile | 20 ---- client/nginx.conf | 17 ---- compose.yaml | 12 +-- docs/architecture.md | 4 +- docs/development.md | 11 ++- package-lock.json | 32 ++++++- package.json | 2 +- server/Dockerfile | 42 --------- server/package.json | 1 + server/src/app.module.ts | 7 ++ server/src/common/client-static.ts | 40 ++++++++ server/src/config/app.config.ts | 4 + server/test/client-static.spec.ts | 141 +++++++++++++++++++++++++++++ 18 files changed, 343 insertions(+), 104 deletions(-) create mode 100644 Dockerfile delete mode 100644 client/Dockerfile delete mode 100644 client/nginx.conf delete mode 100644 server/Dockerfile create mode 100644 server/src/common/client-static.ts create mode 100644 server/test/client-static.spec.ts diff --git a/.dockerignore b/.dockerignore index 33c07fe..bc9d560 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,3 +7,4 @@ node_modules **/*.log data keys +**/*.tsbuildinfo diff --git a/.env.example b/.env.example index f308e45..f592c00 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,8 @@ KEYS_DIR=keys # SQLite database path DB_PATH=data/sessions.db -# Playwright executable (set in Docker; leave empty to use system default) +# Chromium binary to use instead of Playwright's own (not needed in Docker, +# which ships Playwright's chromium-headless-shell) # PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium # Session lifecycle @@ -19,3 +20,7 @@ SESSION_DELETE_CLOSED_DAYS=7 # Playwright trace recording for scenario runs: on | retain-on-failure | off # (traces often reach ~10 MB per run; can be overridden per run in the run modal) PLAYWRIGHT_TRACE_MODE=off + +# Directory with the built client to serve at / (set to "client" in the Docker image; +# leave empty to not serve the UI, e.g. when using the Vite dev server) +# CLIENT_DIR= diff --git a/CHANGELOG.md b/CHANGELOG.md index 30d973d..8bbe39c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. +## 1.19.0 - 2026-09-30 + +Changes since 1.18.0: + +### Changed + +- **Breaking (deployment):** the whole application now runs from a single image and container. The server serves the built client itself (new `CLIENT_DIR` setting, set by the image) next to the API, MCP and Swagger, so the UI moved from http://localhost:13001 to **http://localhost:13000**. The root `Dockerfile` replaces `server/Dockerfile`, `client/Dockerfile` and `client/nginx.conf`, and `compose.yaml` has a single `liqa` service. When upgrading, run `docker compose up -d --build --remove-orphans` to remove the old `server` and `client` containers. +- The image uses Playwright's headless-only Chromium build (`chromium-headless-shell`, always matching the installed Playwright version) with only the libraries it needs, instead of Debian's desktop `chromium` package. Fonts are now DejaVu and Liberation (metric-compatible with Arial/Times) instead of Noto. Together with clearing the npm cache, this shrinks the image from 1.76 GB to 1.07 GB. + ## 1.18.0 - 2026-09-30 Changes since 1.17.0: diff --git a/CLAUDE.md b/CLAUDE.md index e9003e4..e9f29f8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -15,18 +15,14 @@ It is an npm workspace with two packages: - [docs/scenario.md](docs/scenario.md) - scenario execution, script `context` API, versioning, export/import, Playwright traces - [docs/mcp.md](docs/mcp.md) - MCP tool reference - [CHANGELOG.md](CHANGELOG.md) - release notes per version +- [Dockerfile](Dockerfile) - single image: builds client and server, runtime serves both - [.env.example](.env.example) - all configuration variables (validated in `server/src/config/app.config.ts`) ## Default deployment (docker compose) -`compose.yaml` at the repo root runs two containers: +`compose.yaml` at the repo root runs a single `liqa` container, built from the root `Dockerfile`, at http://localhost:13000. The server serves everything: the UI at `/` (the built client, via `CLIENT_DIR`), the REST API at `/api/v1`, MCP at `/mcp`, Swagger at `/docs`. It reads `.env` and mounts `./data` (SQLite DB `data/liqa.db` + stored files) and `./keys`. -| Service | URL | Notes | -|---|---|---| -| `server` | http://localhost:13000 | Built from `server/Dockerfile`; reads `.env`; mounts `./data` (SQLite DB `data/liqa.db` + stored files) and `./keys` | -| `client` | http://localhost:13001 | Built from `client/Dockerfile`; nginx serves the SPA and proxies `/api/` to `server:3000` | - -Rebuild and restart: `docker compose up -d --build`. Check with `docker compose ps`, `curl localhost:13000/health` and `docker compose logs server`. +Rebuild and restart: `docker compose up -d --build`. Check with `docker compose ps`, `curl localhost:13000/health` and `docker compose logs liqa`. The live database is `data/liqa.db`. Because the schema is synced on startup, back it up before deploying entity changes. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b8ac6a3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,87 @@ +# Single image serving the whole application: the NestJS server (API, MCP, +# scheduler) also serves the built client, so one container is enough. + +# ── Client build ────────────────────────────────────────────────────────────── +FROM node:22-slim AS client-build + +WORKDIR /app + +# Root lockfile + workspace manifest so npm ci can resolve the full graph +COPY package*.json ./ +COPY client/package.json ./client/ +RUN npm ci -w client + +COPY client ./client +RUN npm run -w client build + +# ── Server build ────────────────────────────────────────────────────────────── +FROM node:22-slim AS server-build + +WORKDIR /app + +COPY package*.json ./ +COPY server/package.json ./server/ +RUN npm ci -w server + +COPY server/nest-cli.json ./server/ +COPY server/tsconfig*.json ./server/ +COPY server/src ./server/src +RUN npm run -w server build + +# ── Runtime ─────────────────────────────────────────────────────────────────── +FROM node:22-slim AS runtime + +# Shared libraries chrome-headless-shell links against (from `ldd`), plus +# fontconfig and basic fonts for text rendering. Playwright's `--with-deps` +# would also pull in xvfb (with Mesa/LLVM) and extra font packages, which +# headless-only use doesn't need. +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + fontconfig \ + fonts-dejavu-core \ + fonts-liberation \ + libasound2 \ + libatk-bridge2.0-0 \ + libatk1.0-0 \ + libatspi2.0-0 \ + libdbus-1-3 \ + libexpat1 \ + libgbm1 \ + libglib2.0-0 \ + libnspr4 \ + libnss3 \ + libx11-6 \ + libxcb1 \ + libxcomposite1 \ + libxdamage1 \ + libxext6 \ + libxfixes3 \ + libxkbcommon0 \ + libxrandr2 \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY package*.json ./ +COPY server/package.json ./server/ + +# Playwright's headless-only Chromium build, matching the installed Playwright +# version. All browser launches are headless, so the full desktop Chromium +# (GTK, Mesa/LLVM, icon themes) isn't needed. +ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright +RUN npm ci --omit=dev -w server \ + && npx playwright install --only-shell chromium \ + && npm cache clean --force + +COPY --from=server-build /app/server/dist ./dist +COPY --from=client-build /app/client/dist ./client + +# Serve the built client at / (see server/src/common/client-static.ts) +ENV CLIENT_DIR=client + +# Runtime directories (keys and SQLite DB mounted via volumes) +RUN mkdir -p data + +EXPOSE 3000 + +CMD ["node", "dist/main"] diff --git a/client/Dockerfile b/client/Dockerfile deleted file mode 100644 index 0510426..0000000 --- a/client/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -# ── Build stage ─────────────────────────────────────────────────────────────── -FROM node:22-slim AS builder - -WORKDIR /app - -# Copy root lockfile + workspace manifests so npm ci can resolve the full graph -COPY package*.json ./ -COPY client/package.json ./client/ -RUN npm ci -w client - -COPY client ./client -RUN npm run -w client build - -# ── Runtime stage ───────────────────────────────────────────────────────────── -FROM nginx:alpine AS runtime - -COPY --from=builder /app/client/dist /usr/share/nginx/html -COPY client/nginx.conf /etc/nginx/conf.d/default.conf - -EXPOSE 80 diff --git a/client/nginx.conf b/client/nginx.conf deleted file mode 100644 index 8831feb..0000000 --- a/client/nginx.conf +++ /dev/null @@ -1,17 +0,0 @@ -server { - listen 80; - root /usr/share/nginx/html; - index index.html; - - location /api/ { - proxy_pass http://server:3000; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - - location / { - try_files $uri $uri/ /index.html; - } -} diff --git a/compose.yaml b/compose.yaml index 2429e16..6e4d0d7 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,9 +1,9 @@ services: - server: + liqa: build: context: . - dockerfile: server/Dockerfile ports: + # UI, REST API (/api/v1), MCP (/mcp) and Swagger (/docs) - "13000:3000" env_file: - .env @@ -13,11 +13,3 @@ services: # mount key files into the container - ./keys:/app/keys restart: unless-stopped - - client: - build: - context: . - dockerfile: client/Dockerfile - ports: - - "13001:80" - restart: unless-stopped diff --git a/docs/architecture.md b/docs/architecture.md index d14ddf0..0a48d43 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -41,9 +41,9 @@ MCP client (AI agent / VS Code Copilot) ## Client (`client/`) -A React 19 + TypeScript SPA served separately by Vite during development. In Docker Compose the same build artefacts are served statically alongside the API. +A React 19 + TypeScript SPA served by the Vite dev server during development. In the Docker image the server serves the built client itself (`ServeStaticModule`, see `server/src/common/client-static.ts`), from the same origin as the API. -The client calls the server REST endpoints directly — there is no separate BFF layer. Routing uses HashRouter so the Vite proxy and server-side routes are never ambiguous. +The client calls the server REST endpoints directly — there is no separate BFF layer. Routing uses `BrowserRouter`; the server answers any GET outside `/api`, `/mcp`, `/docs` and `/health` with the client's `index.html`, so client-side routes survive a page refresh. The sidebar footer contains the theme switcher and the app version (injected from the workspace root `package.json` at build time). diff --git a/docs/development.md b/docs/development.md index 1ac0d09..296cb10 100644 --- a/docs/development.md +++ b/docs/development.md @@ -30,7 +30,8 @@ Copy `.env.example` to `.env` and fill in the required values before running. | `DB_PATH` | `data/sessions.db` | SQLite database file | | `SESSION_IDLE_TIMEOUT_MINUTES` | `30` | Idle timeout before open sessions are closed | | `SESSION_DELETE_CLOSED_DAYS` | `7` | Retention period for closed sessions | -| `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH` | _(Playwright default)_ | Path to Chromium binary. Set automatically in Docker (`/usr/bin/chromium`). | +| `CLIENT_DIR` | *(empty)* | Directory with the built client to serve at `/` (the Docker image sets it to `client`); empty means the server doesn't serve the UI | +| `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH` | _(Playwright default)_ | Path to a Chromium binary to use instead of Playwright's own. Not set in Docker: the image ships Playwright's `chromium-headless-shell` (matching the Playwright version) under `PLAYWRIGHT_BROWSERS_PATH=/ms-playwright`. | --- @@ -163,6 +164,10 @@ Both workspaces target zero errors. Run lint before committing. ## Building the container +The root `Dockerfile` builds a single image with the whole application: it builds the client and the server in separate stages, and the runtime image runs the server, which also serves the built client (`CLIENT_DIR`). + +The runtime image uses Playwright's headless-only Chromium build (`chromium-headless-shell`) with just the shared libraries it links against, plus DejaVu and Liberation fonts (Liberation is metric-compatible with Arial/Times, so pages lay out as they would with those fonts). All browser launches are headless, so the full desktop Chromium isn't installed. If a new Playwright version needs another library, `ldd` on the `chrome-headless-shell` binary in the image lists what's missing. + ```bash docker compose build ``` @@ -189,7 +194,9 @@ Build and start in one step: docker compose up -d --build ``` -The server API is exposed at **http://localhost:13000**. +Everything is served by the single `liqa` container at **http://localhost:13000**: the UI at `/`, the REST API at `/api/v1`, MCP at `/mcp`, Swagger at `/docs` and health at `/health`. Unknown paths outside those routes get the client's `index.html`, so client-side routes survive a page refresh. + +When switching from the old two-container setup (`server` + `client`), remove the old containers with `docker compose up -d --build --remove-orphans`. SQLite data is persisted in `./data/` and key files are mounted from `./keys/` — both directories are volume-mounted into the container. diff --git a/package-lock.json b/package-lock.json index c7c0a06..39fdc46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "liqa", - "version": "1.18.0", + "version": "1.19.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "liqa", - "version": "1.18.0", + "version": "1.19.0", "workspaces": [ "server", "client" @@ -3387,6 +3387,33 @@ "tslib": "^2.1.0" } }, + "node_modules/@nestjs/serve-static": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@nestjs/serve-static/-/serve-static-5.0.5.tgz", + "integrity": "sha512-AhYx3N9aMwR2cb0w5Nlb5nHNYiAcF74ea/D/xna+PxlXwjmwGN/PpC/5fuMtOwmPBMgOTxNPOnB8C9LDZBSgyw==", + "license": "MIT", + "dependencies": { + "path-to-regexp": "8.4.2" + }, + "peerDependencies": { + "@fastify/static": "^8.0.4 || ^9.0.0", + "@nestjs/common": "^11.0.2", + "@nestjs/core": "^11.0.2", + "express": "^5.0.1", + "fastify": "^5.2.1" + }, + "peerDependenciesMeta": { + "@fastify/static": { + "optional": true + }, + "express": { + "optional": true + }, + "fastify": { + "optional": true + } + } + }, "node_modules/@nestjs/swagger": { "version": "11.2.6", "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-11.2.6.tgz", @@ -16676,6 +16703,7 @@ "@nestjs/core": "^11.1.18", "@nestjs/platform-express": "^11.1.18", "@nestjs/schedule": "^6.1.1", + "@nestjs/serve-static": "^5.0.5", "@nestjs/swagger": "^11.2.6", "@nestjs/typeorm": "^11.0.1", "@playwright/test": "^1.59.1", diff --git a/package.json b/package.json index 4cb1bac..7b314a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liqa", - "version": "1.18.0", + "version": "1.19.0", "private": true, "workspaces": [ "server", diff --git a/server/Dockerfile b/server/Dockerfile deleted file mode 100644 index 38c81f7..0000000 --- a/server/Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -# ── Build stage ────────────────────────────────────────────────────────────── -FROM node:22-slim AS builder - -WORKDIR /app - -COPY package*.json ./ -COPY server/package.json ./server/ -RUN npm ci -w server - -COPY server/nest-cli.json ./server/ -COPY server/tsconfig*.json ./server/ -COPY server/src ./server/src -RUN npm run -w server build - -# ── Runtime stage ───────────────────────────────────────────────────────────── -FROM node:22-slim AS runtime - -# Playwright / Chromium system dependencies -RUN apt-get update && apt-get install -y --no-install-recommends \ - chromium \ - fonts-noto \ - ca-certificates \ - && rm -rf /var/lib/apt/lists/* - -# Tell Playwright to use the system Chromium instead of downloading its own -ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 -ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium - -WORKDIR /app - -COPY package*.json ./ -COPY server/package.json ./server/ -RUN npm ci --omit=dev -w server - -COPY --from=builder /app/server/dist ./dist - -# Runtime directories (keys and SQLite DB mounted via volumes) -RUN mkdir -p data - -EXPOSE 3000 - -CMD ["node", "dist/main"] diff --git a/server/package.json b/server/package.json index 74d53cd..b47bc77 100644 --- a/server/package.json +++ b/server/package.json @@ -25,6 +25,7 @@ "@nestjs/core": "^11.1.18", "@nestjs/platform-express": "^11.1.18", "@nestjs/schedule": "^6.1.1", + "@nestjs/serve-static": "^5.0.5", "@nestjs/swagger": "^11.2.6", "@nestjs/typeorm": "^11.0.1", "@playwright/test": "^1.59.1", diff --git a/server/src/app.module.ts b/server/src/app.module.ts index 4e14182..c87c78a 100644 --- a/server/src/app.module.ts +++ b/server/src/app.module.ts @@ -1,8 +1,10 @@ import { Module } from "@nestjs/common"; import { ConfigModule, ConfigService } from "@nestjs/config"; import { ScheduleModule } from "@nestjs/schedule"; +import { ServeStaticModule } from "@nestjs/serve-static"; import { TypeOrmModule } from "@nestjs/typeorm"; import { BrowserModule } from "./browser/browser.module"; +import { clientStaticOptions } from "./common/client-static"; import { AppConfig, validateAppConfig } from "./config/app.config"; import { CredentialEntity } from "./credential/credential.entity"; import { CredentialModule } from "./credential/credential.module"; @@ -36,6 +38,11 @@ import { SnippetModule } from "./snippet/snippet.module"; validate: validateAppConfig, }), ScheduleModule.forRoot(), + ServeStaticModule.forRootAsync({ + inject: [ConfigService], + useFactory: (config: ConfigService) => + clientStaticOptions(config.get("CLIENT_DIR")), + }), TypeOrmModule.forRootAsync({ inject: [ConfigService], useFactory: (config: ConfigService) => ({ diff --git a/server/src/common/client-static.ts b/server/src/common/client-static.ts new file mode 100644 index 0000000..449258e --- /dev/null +++ b/server/src/common/client-static.ts @@ -0,0 +1,40 @@ +import type { ServeStaticModuleOptions } from "@nestjs/serve-static"; +import type { ServerResponse } from "node:http"; +import * as path from "node:path"; + +/** Server routes that must never fall back to the client's index.html. */ +const SERVER_ROUTES = [ + "/api/{*path}", + "/mcp{*path}", + "/docs{*path}", + "/health", + "/healthz", +]; + +/** + * Serves the built client (SPA) from `clientDir`: static files as they are, + * any other GET outside the server routes gets index.html so client-side + * routes survive a page refresh. Returns no options (nothing served) when + * `clientDir` is empty, e.g. in tests and local development. + */ +export function clientStaticOptions( + clientDir: string, +): ServeStaticModuleOptions[] { + if (!clientDir) return []; + return [ + { + rootPath: path.resolve(clientDir), + exclude: SERVER_ROUTES, + serveStaticOptions: { + setHeaders: (res: ServerResponse, filePath: string) => { + // Vite emits content-hashed files under assets/; index.html must + // always be revalidated so a new deploy is picked up immediately + const cacheControl = filePath.includes(`${path.sep}assets${path.sep}`) + ? "public, max-age=31536000, immutable" + : "no-cache"; + res.setHeader("Cache-Control", cacheControl); + }, + }, + }, + ]; +} diff --git a/server/src/config/app.config.ts b/server/src/config/app.config.ts index 46e6bb8..e266309 100644 --- a/server/src/config/app.config.ts +++ b/server/src/config/app.config.ts @@ -55,6 +55,10 @@ export class AppConfig { @IsString() FILE_CLEANUP_CRON: string = "0 3 * * *"; + /** Directory with the built client to serve at `/`; empty to not serve it. */ + @IsString() + CLIENT_DIR: string = ""; + @IsEnum(TraceMode) // Off by default: traces with screenshots and snapshots easily reach ~10 MB per run PLAYWRIGHT_TRACE_MODE: TraceMode = TraceMode.Off; diff --git a/server/test/client-static.spec.ts b/server/test/client-static.spec.ts new file mode 100644 index 0000000..6efcae1 --- /dev/null +++ b/server/test/client-static.spec.ts @@ -0,0 +1,141 @@ +/** + * Tests serving the built client alongside the server routes: static files, + * the index.html fallback for client-side routes, and that server routes are + * never answered with index.html. + */ + +import { + Controller, + Get, + INestApplication, + Module, + Post, + RequestMethod, +} from "@nestjs/common"; +import { ServeStaticModule } from "@nestjs/serve-static"; +import { NestFactory } from "@nestjs/core"; +import * as fs from "node:fs"; +import * as os from "node:os"; +import * as path from "node:path"; +import request from "supertest"; +import { clientStaticOptions } from "../src/common/client-static"; + +@Controller("things") +class ThingsController { + @Get() + list() { + return [{ id: 1 }]; + } +} + +@Controller() +class RootRoutesController { + @Get("health") + health() { + return { status: "ok" }; + } + + @Post("mcp") + mcp() { + return { jsonrpc: "2.0" }; + } +} + +async function buildApp(clientDir: string): Promise { + // NestFactory (as in main.ts) rather than Test.createTestingModule: the + // serve-static module picks its HTTP loader while the module compiles, + // which needs the HTTP adapter to exist already. + @Module({ + imports: [ServeStaticModule.forRoot(...clientStaticOptions(clientDir))], + controllers: [ThingsController, RootRoutesController], + }) + class ClientStaticTestModule {} + + const app = await NestFactory.create(ClientStaticTestModule, { + logger: false, + }); + // Same prefix setup as main.ts + app.setGlobalPrefix("api/v1", { + exclude: [ + { path: "health", method: RequestMethod.ALL }, + { path: "mcp", method: RequestMethod.ALL }, + ], + }); + await app.init(); + return app; +} + +describe("Client static serving", () => { + let clientDir: string; + let app: INestApplication; + + beforeAll(async () => { + clientDir = fs.mkdtempSync(path.join(os.tmpdir(), "liqa-client-")); + fs.mkdirSync(path.join(clientDir, "assets")); + fs.writeFileSync(path.join(clientDir, "index.html"), "liqa"); + fs.writeFileSync( + path.join(clientDir, "assets", "app-abc123.js"), + "console.log(1);", + ); + app = await buildApp(clientDir); + }); + + afterAll(async () => { + await app.close(); + fs.rmSync(clientDir, { recursive: true, force: true }); + }); + + it("serves index.html at / without caching", async () => { + const res = await request(app.getHttpServer()).get("/").expect(200); + expect(res.text).toBe("liqa"); + expect(res.headers["cache-control"]).toBe("no-cache"); + }); + + it("serves index.html for client-side routes", async () => { + const res = await request(app.getHttpServer()) + .get("/scenarios/123/runs/456") + .expect(200); + expect(res.text).toBe("liqa"); + expect(res.headers["cache-control"]).toBe("no-cache"); + }); + + it("serves hashed assets as immutable", async () => { + const res = await request(app.getHttpServer()) + .get("/assets/app-abc123.js") + .expect(200); + expect(res.text).toBe("console.log(1);"); + expect(res.headers["cache-control"]).toContain("immutable"); + }); + + it("leaves API routes to the server", async () => { + const res = await request(app.getHttpServer()) + .get("/api/v1/things") + .expect(200); + expect(res.body).toEqual([{ id: 1 }]); + }); + + it("returns the server's 404 for unknown API routes, not index.html", async () => { + const res = await request(app.getHttpServer()) + .get("/api/v1/nope") + .expect(404); + expect(res.text).not.toContain("liqa"); + }); + + it("leaves /health and /mcp to the server", async () => { + await request(app.getHttpServer()) + .get("/health") + .expect(200, { status: "ok" }); + await request(app.getHttpServer()) + .post("/mcp") + .expect(201, { jsonrpc: "2.0" }); + const res = await request(app.getHttpServer()).get("/mcp"); + expect(res.text).not.toContain("liqa"); + }); + + it("serves nothing when no client directory is configured", async () => { + const bare = await buildApp(""); + await request(bare.getHttpServer()).get("/").expect(404); + await request(bare.getHttpServer()).get("/api/v1/things").expect(200); + await bare.close(); + }); +});