-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathenv.ts
59 lines (47 loc) · 1.52 KB
/
env.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { loadEnvConfig } from "@next/env";
import { z } from "zod";
const staticEnv = z.object({
NODE_ENV: z
.union([
z.literal("development"),
z.literal("test"),
z.literal("production"),
])
.default("development"),
// for client and server
NEXT_PUBLIC_SITE_URL: z.string().url(),
// for server
DATABASE_USER: z.string().min(1),
DATABASE_PASSWORD: z.string().min(1),
DATABASE_DB: z.string().min(1),
DATABASE_HOST: z.string().min(1),
DATABASE_PORT: z.coerce.number().min(1),
DATABASE_SCHEMA: z.string().min(1),
GOOGLE_CLIENT_ID: z.string().min(1),
GOOGLE_CLIENT_SECRET: z.string().min(1),
NEXTAUTH_URL: z.string().min(1),
NEXTAUTH_SECRET: z.string().min(1),
/* start: otel */
TRACE_EXPORTER_URL: z.string().url().optional().or(z.literal("")),
/* end: otel */
/* start: stripe */
STRIPE_PRICE_ID: z.string().min(1),
STRIPE_SECRET_KEY: z.string().min(1),
STRIPE_WEBHOOK_SECRET: z.string().min(1),
/* end: stripe */
});
const runtimeEnv = z.object({});
export type Schema = z.infer<typeof schema>;
const schema = z.intersection(staticEnv, runtimeEnv);
export function config(kind: "static" | "runtime" = "static") {
const { combinedEnv } = loadEnvConfig(process.cwd());
const res =
kind === "static"
? staticEnv.safeParse(combinedEnv)
: runtimeEnv.safeParse(combinedEnv);
if (res.error) {
console.error("\x1b[31m%s\x1b[0m", "[Errors] environment variables");
console.error(JSON.stringify(res.error.errors, null, 2));
process.exit(1);
}
}