mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
refactor: switch from go to bun
This commit is contained in:
25
apps/server/src/core/config.ts
Normal file
25
apps/server/src/core/config.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { type } from "arktype";
|
||||
import "dotenv/config";
|
||||
|
||||
const envSchema = type({
|
||||
NODE_ENV: type
|
||||
.enumerated("development", "production", "test")
|
||||
.default("development"),
|
||||
DB_FILE_NAME: "string",
|
||||
}).pipe((s) => ({
|
||||
__prod__: s.NODE_ENV === "production",
|
||||
environment: s.NODE_ENV,
|
||||
dbFileName: s.DB_FILE_NAME,
|
||||
}));
|
||||
|
||||
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);
|
||||
Reference in New Issue
Block a user