Skip to content

Commit f871599

Browse files
committed
define vercel url in 2 places to be possible to load from env file
1 parent 0883e9e commit f871599

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/config/process-env.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { envField } from 'astro/config';
33

44
import dotenv from 'dotenv';
55

6-
import { nodeEnvValues, processEnvSchema, VERCEL_URL } from '../schemas/config';
6+
import { nodeEnvValues, processEnvSchema } from '../schemas/config';
77
import { prettyPrintObject } from '../utils/log';
88
import { validateData } from '../utils/validation';
99

@@ -28,6 +28,14 @@ if (!nodeEnvValues.includes(NODE_ENV)) {
2828
const envFileName = `.env.${NODE_ENV}`;
2929
dotenv.config({ path: envFileName });
3030

31+
// Note: must be defined in 2 places (src/schemas/config.ts and src/config/process-env.ts)
32+
// Note: to be possible to load from .env.production file and avoid circular import and astro.config.ts
33+
const VERCEL_URL = (
34+
process.env.VERCEL_PROJECT_PRODUCTION_URL
35+
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
36+
: undefined
37+
) as string;
38+
3139
/*------------------ validate processEnvData -----------------*/
3240

3341
const processEnvData: ProcessEnvType = {

src/schemas/config.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ 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-
159
const domainSubdomainRegex =
1610
/^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,}$/;
1711

1812
const localhostWithPortRegex = /^localhost(:\d{1,5})?$/;
1913

14+
// Note: must be defined in 2 places (src/schemas/config.ts and src/config/process-env.ts)
15+
// Note: to be possible to load from .env.production file and avoid circular import and astro.config.ts
16+
const VERCEL_URL = (
17+
process.env.VERCEL_PROJECT_PRODUCTION_URL
18+
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
19+
: undefined
20+
) as string;
21+
2022
/** runs after astro:env check in astro.config.ts */
2123
export const processEnvSchema = z.object({
2224
NODE_ENV: z.enum(nodeEnvValues),

0 commit comments

Comments
 (0)