Add env check and global env infer type

This commit is contained in:
sianida26 2024-02-23 21:04:59 +07:00
parent b881b1383f
commit 06db4e892e
2 changed files with 17 additions and 1 deletions

15
env.ts Normal file
View File

@ -0,0 +1,15 @@
import { z } from "zod";
const envVariables = z.object({
DATABASE_URL: z.string(),
JWT_SECRET: z.string(),
WS_PORT: z.string(),
WS_HOST: z.string()
});
envVariables.parse(process.env);
declare global {
namespace NodeJS {
interface ProcessEnv extends z.infer<typeof envVariables> {}
}
}

View File

@ -3,7 +3,8 @@
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "check-env": "bun run ./env.ts",
"dev": "bun run check-env && next dev",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"lint": "next lint", "lint": "next lint",