File tree Expand file tree Collapse file tree 3 files changed +9
-14
lines changed Expand file tree Collapse file tree 3 files changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,6 @@ import { config as configFromDotEnv } from "dotenv";
2323
2424export function loadEnv ( env : env , fromWorkerEnv : boolean ) : env {
2525 const Env : env = {
26- //if `fromWokerEnv` is true, then load from the `env` passed as argument to the function,
27- // else if `fromWokerEnv` is false, load from process.env
28- //(or set to '' if value from process.env is undefined) to avoid Error TS2322
2926 CURRENT_ENVIRONMENT : fromWorkerEnv
3027 ? env . CURRENT_ENVIRONMENT
3128 : process . env . CURRENT_ENVIRONMENT || "" ,
Original file line number Diff line number Diff line change 11import { env } from "../src/typeDefinitions/default.types" ;
22import { loadEnv } from "./config" ;
33
4- validateEnv ( ) ;
5-
64/**
75 * Validate if all the required environment variables are set to a non empty value
86 * else throw an error
97 * ---
108 */
119export function validateEnv ( ) {
1210 //pass empty object as env and fromWorkerEnv = false, since this method is should get executed in github actions and not in worker
13- const envLoadedFromProcess : env = loadEnv ( { } , false ) ;
14- const missingEnvVars = Object . keys ( envLoadedFromProcess ) . filter (
15- ( key ) => envLoadedFromProcess [ key ] == ""
11+ const env : env = loadEnv ( { } , false ) ;
12+ const missingEnvVariables = Object . keys ( env ) . filter (
13+ ( key ) => env [ key ] == ""
1614 ) ;
1715
1816 // Logging missing environment variables and throw error if any are missing
19- if ( missingEnvVars . length > 0 ) {
17+ if ( missingEnvVariables . length > 0 ) {
2018 throw new Error (
21- `Missing environment variables: ${ missingEnvVars . join ( ", " ) } `
19+ `Missing environment variables: ${ missingEnvVariables . join ( ", " ) } `
2220 ) ;
2321 } else {
2422 console . log ( "All required environment variables are set." ) ;
2523 }
2624}
25+
26+ validateEnv ( ) ;
Original file line number Diff line number Diff line change @@ -107,12 +107,10 @@ export default {
107107 return new JSONResponse ( response . BAD_SIGNATURE , { status : 401 } ) ;
108108 }
109109 }
110- const envLoadedFromWorker : env = loadEnv ( env , true ) ;
111- return router . handle ( request , envLoadedFromWorker , ctx ) ;
110+ return router . handle ( request , loadEnv ( env , true ) , ctx ) ;
112111 } ,
113112
114113 async scheduled ( req : Request , env : env , ctx : ExecutionContext ) {
115- const envLoadedFromWorker : env = loadEnv ( env , true ) ;
116- ctx . waitUntil ( send ( envLoadedFromWorker ) ) ;
114+ ctx . waitUntil ( send ( loadEnv ( env , true ) ) ) ;
117115 } ,
118116} ;
You can’t perform that action at this time.
0 commit comments