Skip to content

Commit f672b0d

Browse files
authored
review changes
1 parent 16da95d commit f672b0d

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

config/config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ import { config as configFromDotEnv } from "dotenv";
2323

2424
export 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 || "",

config/envVarCheck.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { env } from "../src/typeDefinitions/default.types";
22
import { 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
*/
119
export 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();

src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff 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
};

0 commit comments

Comments
 (0)