chore: relax env parsing for deploy
This commit is contained in:
parent
e1ecf20346
commit
784962947a
1 changed files with 20 additions and 8 deletions
|
|
@ -1,12 +1,24 @@
|
|||
import { z } from "zod"
|
||||
|
||||
const urlField = () =>
|
||||
z.preprocess(
|
||||
(value) => (typeof value === "string" ? value.trim() || undefined : value),
|
||||
z.string().url().optional()
|
||||
)
|
||||
|
||||
const stringField = () =>
|
||||
z.preprocess(
|
||||
(value) => (typeof value === "string" ? value.trim() || undefined : value),
|
||||
z.string().min(1).optional()
|
||||
)
|
||||
|
||||
const envSchema = z.object({
|
||||
BETTER_AUTH_SECRET: z.string().min(1).optional(),
|
||||
BETTER_AUTH_URL: z.string().url().optional(),
|
||||
NEXT_PUBLIC_CONVEX_URL: z.string().url().optional(),
|
||||
CONVEX_INTERNAL_URL: z.string().url().optional(),
|
||||
DATABASE_URL: z.string().min(1).optional(),
|
||||
NEXT_PUBLIC_APP_URL: z.string().url().optional(),
|
||||
BETTER_AUTH_SECRET: stringField().or(z.literal("")).optional(),
|
||||
BETTER_AUTH_URL: urlField().or(z.literal("")).optional(),
|
||||
NEXT_PUBLIC_CONVEX_URL: urlField().or(z.literal("")).optional(),
|
||||
CONVEX_INTERNAL_URL: urlField().or(z.literal("")).optional(),
|
||||
DATABASE_URL: stringField().or(z.literal("")).optional(),
|
||||
NEXT_PUBLIC_APP_URL: urlField().or(z.literal("")).optional(),
|
||||
MACHINE_PROVISIONING_SECRET: z.string().optional(),
|
||||
MACHINE_TOKEN_TTL_MS: z.coerce.number().optional(),
|
||||
FLEET_SYNC_SECRET: z.string().optional(),
|
||||
|
|
@ -20,7 +32,7 @@ const envSchema = z.object({
|
|||
SMTP_TLS: z.string().optional(),
|
||||
MAILER_SENDER_EMAIL: z.string().optional(),
|
||||
REPORTS_CRON_SECRET: z.string().optional(),
|
||||
REPORTS_CRON_BASE_URL: z.string().url().optional(),
|
||||
REPORTS_CRON_BASE_URL: urlField().or(z.literal("")).optional(),
|
||||
})
|
||||
|
||||
const parsed = envSchema.safeParse(process.env)
|
||||
|
|
@ -33,7 +45,7 @@ if (!parsed.success) {
|
|||
const isBuildPhase = process.env.NEXT_PHASE === "phase-production-build"
|
||||
|
||||
function resolveSecret(value: string | undefined, key: string) {
|
||||
if (value) return value
|
||||
if (value && value.length > 0) return value
|
||||
const fallback = isBuildPhase ? `build-placeholder-${key.toLowerCase()}` : `dev-${key.toLowerCase()}`
|
||||
if (process.env.NODE_ENV === "production" && !isBuildPhase) {
|
||||
throw new Error(`${key} must be set in production runtime environment`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue