Initial commit : monorepo seiche (serveur Fastify + web Vite/React, Docker, config VS Code)
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import path from "node:path";
|
||||
import { config as dotenvConfig } from "dotenv";
|
||||
|
||||
// Chargement du .env : d'abord le .env du paquet serveur, puis celui de la racine du repo.
|
||||
// Les variables déjà présentes dans l'environnement ne sont jamais écrasées.
|
||||
dotenvConfig({ path: [".env", "../.env"] });
|
||||
|
||||
export interface Config {
|
||||
port: number;
|
||||
host: string;
|
||||
dataDir: string;
|
||||
sessionTtlMs: number;
|
||||
sessionAbsoluteTtlMs: number;
|
||||
maxLoginAttemptsPerMinute: number;
|
||||
publicDir: string | null;
|
||||
external: {
|
||||
adapter: "example" | "http";
|
||||
baseUrl: string;
|
||||
apiKey: string;
|
||||
healthPath: string;
|
||||
listPath: string;
|
||||
timeoutMs: number;
|
||||
retries: number;
|
||||
cacheTtlMs: number;
|
||||
};
|
||||
}
|
||||
|
||||
function envStr(name: string, fallback: string): string {
|
||||
const value = process.env[name];
|
||||
return value === undefined || value === "" ? fallback : value;
|
||||
}
|
||||
|
||||
function envInt(name: string, fallback: number): number {
|
||||
const raw = process.env[name];
|
||||
if (raw === undefined || raw === "") return fallback;
|
||||
const value = Number.parseInt(raw, 10);
|
||||
if (Number.isNaN(value) || value <= 0) {
|
||||
throw new Error(`Variable d'environnement ${name} invalide : ${raw} (entier positif attendu)`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function loadConfig(): Config {
|
||||
const dataDir = path.resolve(process.cwd(), envStr("SEICHE_DATA_DIR", "./data"));
|
||||
return {
|
||||
port: envInt("SEICHE_PORT", 8787),
|
||||
host: envStr("SEICHE_HOST", "127.0.0.1"),
|
||||
dataDir,
|
||||
sessionTtlMs: envInt("SEICHE_SESSION_TTL_MS", 8 * 60 * 60 * 1000),
|
||||
sessionAbsoluteTtlMs: envInt("SEICHE_SESSION_ABSOLUTE_TTL_MS", 7 * 24 * 60 * 60 * 1000),
|
||||
maxLoginAttemptsPerMinute: envInt("SEICHE_MAX_LOGIN_ATTEMPTS_PER_MINUTE", 5),
|
||||
publicDir: process.env.SEICHE_PUBLIC_DIR ?? null,
|
||||
external: {
|
||||
adapter: (process.env.SEICHE_EXTERNAL_ADAPTER ?? "example") as "example" | "http",
|
||||
baseUrl: envStr("SEICHE_EXTERNAL_BASE_URL", ""),
|
||||
apiKey: envStr("SEICHE_EXTERNAL_API_KEY", ""),
|
||||
healthPath: envStr("SEICHE_EXTERNAL_HEALTH_PATH", "/health"),
|
||||
listPath: envStr("SEICHE_EXTERNAL_LIST_PATH", "/items"),
|
||||
timeoutMs: envInt("SEICHE_EXTERNAL_TIMEOUT_MS", 10_000),
|
||||
retries: envInt("SEICHE_EXTERNAL_RETRIES", 2),
|
||||
cacheTtlMs: envInt("SEICHE_EXTERNAL_CACHE_TTL_MS", 30_000),
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user