From 12274a84b27b26d36208f000f07d5c17a3f5b186 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 26 Jun 2022 14:41:31 +0300 Subject: [PATCH] Fix .env number validation errors --- backend/src/env.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/env.ts b/backend/src/env.ts index 4698d9b3..13cbbdb7 100644 --- a/backend/src/env.ts +++ b/backend/src/env.ts @@ -19,19 +19,22 @@ const envType = z.object({ PHISHERMAN_API_KEY: z.string().optional(), - API_PORT: z.number().min(1).max(65535), + API_PORT: z.preprocess((v) => Number(v), z.number().min(1).max(65535)), DOCKER_MYSQL_PASSWORD: z.string().optional(), // Included here for the DB_PASSWORD default in development DB_HOST: z.string().optional().default("mysql"), - DB_PORT: z.number().optional().default(3306), + DB_PORT: z + .preprocess((v) => Number(v), z.number()) + .optional() + .default(3306), DB_USER: z.string().optional().default("zeppelin"), DB_PASSWORD: z.string().optional(), // Default is set to DOCKER_MYSQL_PASSWORD further below DB_DATABASE: z.string().optional().default("zeppelin"), }); let toValidate = {}; -const envPath = path.join(rootDir, "../.env"); +const envPath = path.join(rootDir, ".env"); if (fs.existsSync(envPath)) { const buf = fs.readFileSync(envPath); toValidate = dotenv.parse(buf);