mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
0b218d53b2
Co-hosted NestJS app behind the existing Express server via a strangler-fig dispatcher, sharing the same better-sqlite3 connection and JWT httpOnly cookie. Additive and dormant: default routing stays on Express, Nest only serves its own /api/_nest diagnostics until a module opts in. F1 @trek/shared Zod contract package; F2 Nest bootstrap co-hosted (fall-through, single Dockerfile/port); F3 shared better-sqlite3 provider; F4 JWT cookie auth guard (+ @CurrentUser, admin guard); F5 Zod validation pipe + error-envelope parity; F6 Nest test + coverage gates; F7 per-prefix strangler toggle (env, default Express); F8 CI build/typecheck/test/coverage. Remaining F4/F6/F8 checklist items (trip-access + permission levels + MFA policy, e2e harness/seed + 80% gate, Nest↔Express parity test, Playwright PR-comment workflow) are tracked on the first consuming module cards (L1/A1/C1).
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { describe, it, expect, afterEach } from 'vitest';
|
|
import { getNestPrefixes, makeNestPathMatcher } from '../../../src/nest/strangler';
|
|
|
|
describe('strangler toggle', () => {
|
|
const original = process.env.NEST_PREFIXES;
|
|
afterEach(() => {
|
|
if (original === undefined) delete process.env.NEST_PREFIXES;
|
|
else process.env.NEST_PREFIXES = original;
|
|
});
|
|
|
|
it('defaults to /api/_nest when NEST_PREFIXES is unset', () => {
|
|
delete process.env.NEST_PREFIXES;
|
|
expect(getNestPrefixes()).toEqual(['/api/_nest']);
|
|
});
|
|
|
|
it('parses NEST_PREFIXES (comma-separated, trimmed)', () => {
|
|
process.env.NEST_PREFIXES = '/api/weather, /api/airports';
|
|
expect(getNestPrefixes()).toEqual(['/api/weather', '/api/airports']);
|
|
});
|
|
|
|
it('treats an empty NEST_PREFIXES as "all routes on legacy"', () => {
|
|
process.env.NEST_PREFIXES = '';
|
|
expect(getNestPrefixes()).toEqual([]);
|
|
});
|
|
|
|
it('matches exact prefixes and subpaths but not lookalikes', () => {
|
|
const match = makeNestPathMatcher(['/api/_nest']);
|
|
expect(match('/api/_nest')).toBe(true);
|
|
expect(match('/api/_nest/health')).toBe(true);
|
|
expect(match('/api/_nestxyz')).toBe(false);
|
|
expect(match('/api/health')).toBe(false);
|
|
});
|
|
});
|