|
| 1 | +import { createEnv } from "@t3-oss/env-nextjs" |
| 2 | +import { z } from "zod" |
| 3 | + |
| 4 | +const PORT = 6111 |
| 5 | + |
| 6 | +// coerce is needed for non-string values, because k8s supports only string env |
| 7 | +export const env = createEnv({ |
| 8 | + server: { |
| 9 | + PORT: z.coerce.number().min(1).max(65535).default(PORT), |
| 10 | + NODE_ENV: z.enum(["development", "production"]).default("development"), |
| 11 | + // PUBLIC_URL: z.string().default(`https://polinet.cc`), |
| 12 | + // LOG_LEVEL: z.string().default("DEBUG"), |
| 13 | + |
| 14 | + DB_HOST: z.string().min(1), |
| 15 | + DB_PORT: z.coerce.number().min(1).max(65535).default(5432), |
| 16 | + DB_USER: z.string().min(1), |
| 17 | + DB_PASS: z.string().min(1), |
| 18 | + DB_NAME: z.string().min(3).default("url_shortener"), |
| 19 | + }, |
| 20 | + |
| 21 | + runtimeEnv: { |
| 22 | + PORT: process.env.PORT, |
| 23 | + DB_HOST: process.env.DB_HOST, |
| 24 | + DB_PORT: process.env.DB_PORT, |
| 25 | + DB_USER: process.env.DB_USER, |
| 26 | + DB_PASS: process.env.DB_PASS, |
| 27 | + DB_NAME: process.env.DB_NAME, |
| 28 | + NODE_ENV: process.env.NODE_ENV, |
| 29 | + }, |
| 30 | + |
| 31 | + /** |
| 32 | + * By default, this library will feed the environment variables directly to |
| 33 | + * the Zod validator. |
| 34 | + * |
| 35 | + * This means that if you have an empty string for a value that is supposed |
| 36 | + * to be a number (e.g. `PORT=` in a ".env" file), Zod will incorrectly flag |
| 37 | + * it as a type mismatch violation. Additionally, if you have an empty string |
| 38 | + * for a value that is supposed to be a string with a default value (e.g. |
| 39 | + * `DOMAIN=` in an ".env" file), the default value will never be applied. |
| 40 | + * |
| 41 | + * In order to solve these issues, we recommend that all new projects |
| 42 | + * explicitly specify this option as true. |
| 43 | + */ |
| 44 | + emptyStringAsUndefined: true, |
| 45 | +}) |
0 commit comments