Files
lt-auth-proxy/src/env.ts
Max P. 53939d051a feat(env): add verbose environment variable support
- Introduces a static getter to fetch the VERBOSE environment variable
2025-05-11 09:54:26 +02:00

69 lines
2.1 KiB
TypeScript

/**
* Environment configuration for lt-auth-proxy.
* All properties are lazily evaluated and cached on first access.
*/
export class Env {
private static _proxyHost?: string;
private static _proxyPort?: number;
private static _apiKeys?: string[];
private static _ltServerHost?: string;
private static _ltServerPort?: number;
private static getEnv(key: string, required = false): string | undefined {
const value = Deno.env.get(key);
if (required && (!value || value.trim() === '')) {
throw new Error(`Missing required environment variable: ${key}`);
}
return value;
}
/** Hostname for the proxy (default: 0.0.0.0) */
static get proxyHost(): string {
if (this._proxyHost === undefined) {
this._proxyHost = this.getEnv('PROXY_HOST') || '0.0.0.0';
}
return this._proxyHost;
}
/** Port for the proxy (default: 8011) */
static get proxyPort(): number {
if (this._proxyPort === undefined) {
this._proxyPort = Number(this.getEnv('PROXY_PORT') || 8011);
}
return this._proxyPort;
}
/** List of allowed API keys (required) */
static get apiKeys(): string[] {
if (this._apiKeys === undefined) {
const raw = this.getEnv('API_KEYS', true)!;
this._apiKeys = raw.split(',').map((k) => k.trim()).filter((k) =>
k.length > 0
);
}
return this._apiKeys;
}
/** Hostname of the LanguageTool backend (default: localhost) */
static get ltServerHost(): string {
if (this._ltServerHost === undefined) {
this._ltServerHost = this.getEnv('LT_SERVER_HOST') || 'localhost';
}
return this._ltServerHost;
}
/** Port of the LanguageTool backend (default: 8010) */
static get ltServerPort(): number {
if (this._ltServerPort === undefined) {
this._ltServerPort = Number(this.getEnv('LT_SERVER_PORT') || 8010);
}
return this._ltServerPort;
}
/** VERBOSE */
static get verbose(): boolean {
return this.getEnv('VERBOSE') === 'true';
}
}