mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
724c88c201
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { readEnv, type AppEnv } from '../../app-config';
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
/**
|
|
* DI-friendly access to the RUNTIME-TOGGLED env values (DEMO_MODE, NODE_ENV,
|
|
* APP_VERSION, OIDC_*, …). Every method delegates to readEnv() at call time —
|
|
* never snapshot a namespace into a field or the constructor, or the ~60 tests
|
|
* that mutate process.env mid-lifetime break.
|
|
*
|
|
* Boot-stable values are NOT accessed through this service; inject their
|
|
* registerAs token instead (see tokens.ts).
|
|
*/
|
|
@Injectable()
|
|
export class RuntimeEnvService {
|
|
/** The full live-derived env — prefer the convenience getters where one exists. */
|
|
env(): AppEnv {
|
|
return readEnv();
|
|
}
|
|
|
|
isDemoMode(): boolean {
|
|
return readEnv().demo.enabled;
|
|
}
|
|
|
|
/**
|
|
* True when somebody other than this instance's admin owns its configuration.
|
|
* Runtime-toggled like DEMO_MODE, so never cache the result in a field.
|
|
*/
|
|
isManaged(): boolean {
|
|
return readEnv().managed.enabled;
|
|
}
|
|
|
|
/** True only under exactly NODE_ENV='test' (case-sensitive, like the :memory: DB pick). */
|
|
isTest(): boolean {
|
|
return readEnv().app.isTest;
|
|
}
|
|
|
|
nodeEnv(): string | undefined {
|
|
return readEnv().app.nodeEnv;
|
|
}
|
|
|
|
isProduction(): boolean {
|
|
return readEnv().app.isProduction;
|
|
}
|
|
|
|
isDevelopment(): boolean {
|
|
return readEnv().app.isDevelopment;
|
|
}
|
|
|
|
/** Raw APP_VERSION — call sites keep their own fallback ('0.0.0' vs package.json vs semver). */
|
|
appVersion(): string | undefined {
|
|
return readEnv().app.appVersion;
|
|
}
|
|
|
|
/** Raw APP_URL — call sites keep their own trailing-slash handling. */
|
|
appUrl(): string | undefined {
|
|
return readEnv().app.appUrl;
|
|
}
|
|
}
|