mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
22 lines
516 B
TypeScript
22 lines
516 B
TypeScript
import { type } from "arktype";
|
|
import "dotenv/config";
|
|
|
|
const envSchema = type({
|
|
NODE_ENV: type.enumerated("development", "production", "test").default("production"),
|
|
}).pipe((s) => ({
|
|
__prod__: s.NODE_ENV === "production",
|
|
environment: s.NODE_ENV,
|
|
}));
|
|
|
|
const parseConfig = (env: unknown) => {
|
|
const result = envSchema(env);
|
|
|
|
if (result instanceof type.errors) {
|
|
throw new Error(`Invalid environment variables: ${result.toString()}`);
|
|
}
|
|
|
|
return result;
|
|
};
|
|
|
|
export const config = parseConfig(process.env);
|