aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/lib/env.server.ts
blob: 314bc9dbe20d93b39ddff1915689211a3279273e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { zodEnv } from "./environment";

import process from "node:process";
import { z } from "zod";

try {
	zodEnv.parse(process.env);
} catch (err) {
	if (process.env.NODE_ENV === "production") {
		// do nothihng
		console.log("production");
	} else if (err instanceof z.ZodError) {
		const { fieldErrors } = err.flatten();
		const errorMessage = Object.entries(fieldErrors)
			.map(([field, errors]) => (errors ? `${field}: ${errors.join(", ")}` : field))
			.join("\n  ");
		throw new Error(`Missing environment variables:\n  ${errorMessage}`);
	}
}