zerobyte/app/server/core/config.ts
Nico 55e27ef0b5
feat: server timeout env (#219)
* feat: increase server idle timeout and allow to modify it via env

* chore(app): move auth middleware to individual controller

To clean up de main app.ts file

* chore: remove console.log
2025-12-22 17:34:27 +01:00

26 lines
731 B
TypeScript

import { type } from "arktype";
import "dotenv/config";
const envSchema = type({
NODE_ENV: type.enumerated("development", "production", "test").default("production"),
SERVER_IP: 'string = "localhost"',
SERVER_IDLE_TIMEOUT: 'string.integer.parse = "60"',
}).pipe((s) => ({
__prod__: s.NODE_ENV === "production",
environment: s.NODE_ENV,
serverIp: s.SERVER_IP,
serverIdleTimeout: s.SERVER_IDLE_TIMEOUT,
}));
const parseConfig = (env: unknown) => {
const result = envSchema(env);
if (result instanceof type.errors) {
console.error(`Environment variable validation failed: ${result.toString()}`);
throw new Error("Invalid environment variables");
}
return result;
};
export const config = parseConfig(process.env);