Skip to content

Commit a9841cf

Browse files
committed
Refactor environment variable handling in YouTube app
- Introduced a new mechanism to skip environment validation during tests and CI, enhancing flexibility in different environments. - Added default build configuration for environment variables, streamlining the setup process for development and testing. Made-with: Cursor
1 parent eff7d55 commit a9841cf

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

apps/youtube/src/lib/env.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,25 @@ const envSchema = z.object({
1717

1818
export type Env = z.infer<typeof envSchema>;
1919

20-
const isTest = process.env.NODE_ENV === "test" || process.env.VITEST;
20+
const skipValidation =
21+
process.env.NODE_ENV === "test" ||
22+
!!process.env.VITEST ||
23+
!!process.env.CI ||
24+
!!process.env.SKIP_ENV_VALIDATION;
25+
26+
const BUILD_DEFAULTS: Env = {
27+
POSTGRES_URL: "postgresql://build:build@localhost/build",
28+
AUTH_SECRET: "build-secret",
29+
AUTH_GOOGLE_ID: "build-google-id",
30+
AUTH_GOOGLE_SECRET: "build-google-secret",
31+
YOUTUBE_API_KEY: "build-api-key",
32+
};
2133

2234
function loadEnv(): Env {
2335
const result = envSchema.safeParse(process.env);
2436
if (result.success) return result.data;
25-
if (isTest) {
26-
return {
27-
POSTGRES_URL: "postgresql://test:test@localhost/test",
28-
AUTH_SECRET: "test-secret",
29-
AUTH_GOOGLE_ID: "test-google-id",
30-
AUTH_GOOGLE_SECRET: "test-google-secret",
31-
YOUTUBE_API_KEY: "test-api-key",
32-
...process.env,
33-
} as Env;
37+
if (skipValidation) {
38+
return { ...BUILD_DEFAULTS, ...process.env } as Env;
3439
}
3540
throw result.error;
3641
}

0 commit comments

Comments
 (0)