- database.ts 导出db常量替代getDb()函数 - env.ts JWT_SECRET/ES_URL/NEO4J_URL改optional加DEV_MODE - neo4j.ts driver惰性创建+try/catch+connectionTimeout:3000 - health/lifecycle改用Drizzle原生查询 - textbooks.schema修复integer到int+导出NewTextbook类型 - 新建chapters/knowledge-points/questions三模块CRUD - knowledge-points含Neo4j前置依赖图非阻塞查询 - content-init.sql创建4张表 端到端验证: textbooks/chapters/knowledge-points/questions全CRUD通过
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { z } from "zod";
|
|
|
|
const envSchema = z.object({
|
|
PORT: z.string().default("3005"),
|
|
DATABASE_URL: z.string().url(),
|
|
REDIS_URL: z.string().url().optional(),
|
|
NEO4J_URL: z.string().url().optional(),
|
|
NEO4J_PASSWORD: z.string().optional(),
|
|
ES_URL: z.string().url().optional(),
|
|
JWT_SECRET: z.string().optional(),
|
|
JWT_ISSUER: z.string().default("next-edu-cloud"),
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: z.string().url().optional(),
|
|
LOG_LEVEL: z
|
|
.enum(["fatal", "error", "warn", "info", "debug", "trace"])
|
|
.default("info"),
|
|
NODE_ENV: z
|
|
.enum(["development", "production", "test"])
|
|
.default("development"),
|
|
DEV_MODE: z.string().optional().default("false"),
|
|
});
|
|
|
|
export type Env = z.infer<typeof envSchema>;
|
|
|
|
export function loadEnv(): Env {
|
|
const result = envSchema.safeParse(process.env);
|
|
if (!result.success) {
|
|
console.error(
|
|
"❌ Invalid environment variables:",
|
|
result.error.flatten().fieldErrors,
|
|
);
|
|
throw new Error("Invalid environment configuration");
|
|
}
|
|
return result.data;
|
|
}
|
|
|
|
export const env = loadEnv();
|