- allow the vite dev server origins in development and the compose port origins in production; CORS_ORIGINS overrides both - set NODE_ENV=production in the runtime docker image - document both settings in .env.example and the development docs - bump version to 1.19.3
79 lines
1.7 KiB
TypeScript
79 lines
1.7 KiB
TypeScript
import { plainToInstance } from "class-transformer";
|
|
import {
|
|
IsEnum,
|
|
IsInt,
|
|
IsString,
|
|
Max,
|
|
Min,
|
|
validateSync,
|
|
} from "class-validator";
|
|
|
|
import { appPackage } from "../common/app-package";
|
|
|
|
export enum TraceMode {
|
|
On = "on",
|
|
RetainOnFailure = "retain-on-failure",
|
|
Off = "off",
|
|
}
|
|
|
|
export class AppConfig {
|
|
/** `production` in the Docker image; also selects the default CORS origins. */
|
|
@IsString()
|
|
NODE_ENV: string = "development";
|
|
|
|
/** Comma-separated origins allowed to call the API cross-origin; empty = default for NODE_ENV. */
|
|
@IsString()
|
|
CORS_ORIGINS: string = "";
|
|
|
|
@IsInt()
|
|
@Min(1)
|
|
@Max(65535)
|
|
PORT: number = 3000;
|
|
|
|
@IsString()
|
|
APP_NAME: string = appPackage().name;
|
|
|
|
@IsString()
|
|
APP_VERSION: string = appPackage().version;
|
|
|
|
@IsString()
|
|
DB_PATH: string = "data/liqa.db";
|
|
|
|
@IsInt()
|
|
@Min(1)
|
|
SESSION_IDLE_TIMEOUT_MINUTES: number = 30;
|
|
|
|
@IsInt()
|
|
@Min(1)
|
|
SESSION_DELETE_CLOSED_DAYS: number = 7;
|
|
|
|
@IsString()
|
|
FILES_DIR: string = "data/files";
|
|
|
|
@IsInt()
|
|
@Min(1)
|
|
FILE_RUN_EXPIRATION_DAYS: number = 7;
|
|
|
|
@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;
|
|
}
|
|
|
|
export function validateAppConfig(config: Record<string, unknown>): AppConfig {
|
|
const validated = plainToInstance(AppConfig, config, {
|
|
enableImplicitConversion: true,
|
|
});
|
|
const errors = validateSync(validated, { skipMissingProperties: false });
|
|
if (errors.length > 0) {
|
|
throw new Error(errors.toString());
|
|
}
|
|
return validated;
|
|
}
|