Skip to content

Commit 4bde2c0

Browse files
committed
fix zod schema
1 parent 13b5c32 commit 4bde2c0

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/config/process-env.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { envField } from 'astro/config';
33

44
import dotenv from 'dotenv';
55

6-
import { nodeEnvValues, processEnvSchema } from '../schemas/config';
6+
import { nodeEnvValues, processEnvSchema, VERCEL_URL } from '../schemas/config';
77
import { prettyPrintObject } from '../utils/log';
8-
import { getHostnameFromUrl } from '../utils/urls';
98
import { validateData } from '../utils/validation';
109

10+
// import { getHostnameFromUrl } from '../utils/urls';
11+
1112
import type { ProcessEnvType } from '../types/config';
1213

1314
/*------------------ load .env file -----------------*/
@@ -29,10 +30,6 @@ dotenv.config({ path: envFileName });
2930

3031
/*------------------ validate processEnvData -----------------*/
3132

32-
const VERCEL_URL = process.env.VERCEL_PROJECT_PRODUCTION_URL
33-
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
34-
: '';
35-
3633
const processEnvData: ProcessEnvType = {
3734
NODE_ENV: process.env.NODE_ENV,
3835
PREVIEW_MODE: process.env.PREVIEW_MODE,

src/schemas/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export const booleanValues = ['true', 'false', ''] as const;
66
export const modeValues = ['light', 'dark'] as const;
77
export const themeValues = ['default-light', 'default-dark', 'green-light', 'green-dark'] as const;
88

9+
export const VERCEL_URL = (
10+
process.env.VERCEL_PROJECT_PRODUCTION_URL
11+
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
12+
: undefined
13+
) as string;
14+
915
const domainSubdomainRegex =
1016
/^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,}$/;
1117

@@ -19,7 +25,7 @@ export const processEnvSchema = z.object({
1925
.transform((value) => value === 'true')
2026
.default(false),
2127
// ensure no trailing slash
22-
SITE_URL: z.url().regex(/[^/]$/, 'SITE_URL should not end with a slash "/"'),
28+
SITE_URL: z.url().regex(/[^/]$/, 'SITE_URL should not end with a slash "/"').default(VERCEL_URL),
2329
PLAUSIBLE_SCRIPT_URL: z.url().or(z.literal('')).optional(),
2430
PLAUSIBLE_DOMAIN: z
2531
.string()

0 commit comments

Comments
 (0)