From bc298541a3546bee89789ffbe605455dfdf977d6 Mon Sep 17 00:00:00 2001 From: Yuta Hiroto Date: Tue, 7 Jan 2025 21:55:39 +0900 Subject: [PATCH] feat(site): add dotenv section --- .internal/site/.vitepress/config.mts | 4 ++++ .internal/site/src/introduction/dotenv.md | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .internal/site/src/introduction/dotenv.md diff --git a/.internal/site/.vitepress/config.mts b/.internal/site/.vitepress/config.mts index a30f0a9..295296e 100644 --- a/.internal/site/.vitepress/config.mts +++ b/.internal/site/.vitepress/config.mts @@ -46,6 +46,10 @@ export default defineConfig({ text: "Routing", link: "/introduction/routing", }, + { + text: "Dotenv", + link: "/introduction/dotenv", + }, ], }, { diff --git a/.internal/site/src/introduction/dotenv.md b/.internal/site/src/introduction/dotenv.md new file mode 100644 index 0000000..c77d5c0 --- /dev/null +++ b/.internal/site/src/introduction/dotenv.md @@ -0,0 +1,17 @@ +# Dotenv + +Dotenv is the de facto standard, but it lacks validation, making it prone to errors. In this template, we use zod to validate the required environment variables in files like `next.config.ts`. If any required variables are missing or invalid, the application will fail to execute. This approach ensures robustness at runtime. + +::: code-group + +<<< ../../../../.env.sample + +<<< ../../../../env.ts + +::: + +If you need to add new environment variables, make sure to add them to both `.env` and `.env.test`, and update the `env.ts` with the corresponding zod validation. + +## Why not use .env.local? + +Prisma can read the `.env` file, and the `DATABASE_URL` is a required key for migration. While Next.js prioritizes `.env.local`, splitting the dotenv files can be inefficient. Therefore, to maintain consistency with Prisma, this template uses `.env`.