Scaffold and Phase 0-1
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { config as loadEnv } from "dotenv";
|
||||
import { z } from "zod";
|
||||
|
||||
loadEnv();
|
||||
|
||||
const schema = z.object({
|
||||
NODE_ENV: z.enum(["development", "production", "test"]).default("production"),
|
||||
PORT: z.coerce.number().int().positive().default(8811),
|
||||
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
|
||||
GATEWAY_VERSION: z.string().default("0.1.0"),
|
||||
ENABLED_PLUGINS: z.string().default(""),
|
||||
AGENT_TOKENS: z.string().default(""),
|
||||
PLUGINS_DIR: z.string().default("./dist/plugins"),
|
||||
});
|
||||
|
||||
const parsed = schema.safeParse(process.env);
|
||||
if (!parsed.success) {
|
||||
// Boot-time validation failure: print and exit. Never let a misconfigured
|
||||
// gateway start up partially.
|
||||
console.error("Invalid environment configuration:", parsed.error.format());
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
export const env = parsed.data;
|
||||
|
||||
export const enabledPlugins = env.ENABLED_PLUGINS
|
||||
? env.ENABLED_PLUGINS.split(",")
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
Reference in New Issue
Block a user