@@ -29,20 +29,29 @@ for (const [key, value] of Object.entries(process.env)) {
2929 }
3030}
3131
32+ const optionalString = ( schema : z . ZodString ) =>
33+ z . preprocess (
34+ ( value ) =>
35+ typeof value === "string" && value . trim ( ) . length === 0
36+ ? undefined
37+ : value ,
38+ schema . optional ( ) ,
39+ ) ;
40+
3241const envSchema = z . object ( {
3342 NODE_ENV : z . enum ( [ "development" , "test" , "production" ] ) . default ( "development" ) ,
3443 PORT : z . coerce . number ( ) . int ( ) . positive ( ) . default ( 3005 ) ,
3544 FRONT_DEV_PORT : z . coerce . number ( ) . int ( ) . positive ( ) . default ( 3000 ) ,
36- CLIENT_ORIGIN : z . string ( ) . url ( ) . optional ( ) ,
37- FEDERATION_ORIGIN : z . string ( ) . url ( ) . optional ( ) ,
38- APP_CONFIG_PATH : z . string ( ) . optional ( ) ,
45+ CLIENT_ORIGIN : optionalString ( z . string ( ) . url ( ) ) ,
46+ FEDERATION_ORIGIN : optionalString ( z . string ( ) . url ( ) ) ,
47+ APP_CONFIG_PATH : optionalString ( z . string ( ) ) ,
3948 FEATURED_STREAMERS_CRON : z . string ( ) . default ( "*/5 * * * *" ) ,
4049 CACHE_PROVIDER : z . enum ( [ "memory" , "redis" ] ) . default ( "memory" ) ,
4150 RATE_LIMIT_PROVIDER : z . enum ( [ "memory" , "redis" ] ) . default ( "memory" ) ,
42- REDIS_URL : z . string ( ) . url ( ) . optional ( ) ,
51+ REDIS_URL : optionalString ( z . string ( ) . url ( ) ) ,
4352 RUNTIME_ROLE : z . enum ( [ "api" , "worker" , "all" ] ) . default ( "all" ) ,
44- SERVICE_API_KEYS : z . string ( ) . optional ( ) ,
45- TOKEN_SECRET : z . string ( ) . min ( 1 ) . optional ( ) ,
53+ SERVICE_API_KEYS : optionalString ( z . string ( ) ) ,
54+ TOKEN_SECRET : optionalString ( z . string ( ) . min ( 1 ) ) ,
4655} ) ;
4756
4857const parsed = envSchema . parse ( process . env ) ;
0 commit comments