aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/env.ts
diff options
context:
space:
mode:
authorJan T <jans.tuomi@gmail.com>2024-02-14 17:18:30 +0200
committerGitHub <noreply@github.com>2024-02-14 10:18:30 -0500
commit2af066038351ab0634c359a688fe712a539992b4 (patch)
tree3ca4bb30f4813ff7e7d87354c5fdd83dcb19cb59 /src/lib/env.ts
parent50525ad8810de356856eb098a1e0882ce3607b9f (diff)
Optimize docker image size (#91)
* Move prisma to runtime dependencies * Optimize Dockerfile and build script * Fix: remove mention of generated next-env.d.ts in Dockerfile * Add missing reset.d.ts file to Dockerfile * Remove compression steps from Dockerfile and entrypoint script * Add an env file with mocked env vars added for Docker production builds * Use server actions to get runtime env vars * Refactor types and names * Rollback serverActions, use parsed Zod object for runtime env * Reintroduce featureFlags object to avoid passing secret envs to the frontend * Improve string to boolean coercion Co-authored-by: Sebastien Castiel <sebastien@castiel.me> * Run prettier autoformat * Fix type issue, rename function to match behaviour better --------- Co-authored-by: Lauri Vuorela <lauri.vuorela@gmail.com> Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
Diffstat (limited to 'src/lib/env.ts')
-rw-r--r--src/lib/env.ts20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/lib/env.ts b/src/lib/env.ts
index 927e756..920df14 100644
--- a/src/lib/env.ts
+++ b/src/lib/env.ts
@@ -1,5 +1,10 @@
import { ZodIssueCode, z } from 'zod'
+const interpretEnvVarAsBool = (val: unknown): boolean => {
+ if (typeof val !== 'string') return false
+ return ['true', 'yes', '1', 'on'].includes(val.toLowerCase())
+}
+
const envSchema = z
.object({
POSTGRES_URL_NON_POOLING: z.string().url(),
@@ -12,14 +17,23 @@ const envSchema = z
? `https://${process.env.VERCEL_URL}`
: 'http://localhost:3000',
),
- NEXT_PUBLIC_ENABLE_EXPENSE_DOCUMENTS: z.coerce.boolean().default(false),
+ NEXT_PUBLIC_ENABLE_EXPENSE_DOCUMENTS: z.preprocess(
+ interpretEnvVarAsBool,
+ z.boolean().default(false),
+ ),
S3_UPLOAD_KEY: z.string().optional(),
S3_UPLOAD_SECRET: z.string().optional(),
S3_UPLOAD_BUCKET: z.string().optional(),
S3_UPLOAD_REGION: z.string().optional(),
S3_UPLOAD_ENDPOINT: z.string().optional(),
- NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT: z.coerce.boolean().default(false),
- NEXT_PUBLIC_ENABLE_CATEGORY_EXTRACT: z.coerce.boolean().default(false),
+ NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT: z.preprocess(
+ interpretEnvVarAsBool,
+ z.boolean().default(false),
+ ),
+ NEXT_PUBLIC_ENABLE_CATEGORY_EXTRACT: z.preprocess(
+ interpretEnvVarAsBool,
+ z.boolean().default(false),
+ ),
OPENAI_API_KEY: z.string().optional(),
})
.superRefine((env, ctx) => {