Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

1.6 KB
Raw Blame
/**
 * Global binding of @nestjs/config onto TREK's app-config layer.
 *
 * INVARIANTS — breaking either silently breaks ~60 env-mutating tests:
 *  - `cache: false`, always. `cache: true` would freeze ConfigService lookups
 *    for the whole app lifetime; the runtime-toggled vars (DEMO_MODE, NODE_ENV,
 *    OIDC_*, …) must stay live via RuntimeEnvService/readEnv().
 *  - No `validate`/`validationSchema` here. Fail-fast validation runs exactly
 *    once, from the production entrypoint (src/app-config/boot-validate.ts) —
 *    buildApp() is invoked dozens of times per test run and must stay
 *    side-effect-free.
 *  - `ignoreEnvFile: true`, always. dotenv is loaded ONCE in index.ts; tests
 *    deliberately never load .env, and reading it here would leak a
 *    developer's local server/.env into every integration test.
 *
 * The framework's ConfigModule is aliased ONLY inside this file: app.module.ts
 * already imports a local `ConfigModule` (the /api/config endpoint module), so
 * the alias keeps the two from colliding anywhere else.
 */
import { DataPathsService } from './data-paths.service';
import { RuntimeEnvService } from './runtime-env.service';
import { BOOT_STABLE_TOKENS } from './tokens';
import { Global, Module } from '@nestjs/common';
import { ConfigModule as NestConfigModule } from '@nestjs/config';

@Global()
@Module({
  imports: [
    NestConfigModule.forRoot({
      isGlobal: true,
      ignoreEnvFile: true,
      cache: false,
      load: BOOT_STABLE_TOKENS,
    }),
  ],
  providers: [RuntimeEnvService, DataPathsService],
  exports: [RuntimeEnvService, DataPathsService],
})
export class AppConfigModule {}