Skip to content

Commit 824359e

Browse files
authored
made changes from feature branch to test branch for testing
1 parent f2af5dd commit 824359e

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

config/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export function loadEnv (
2626
fromWorkerEnv: boolean
2727
): env {
2828
const Env:env = {
29+
//if `fromWokerEnv` is true, then load from the `env` passed as argument to the function,
30+
// else if `fromWokerEnv` is false, load from process.env
31+
//(or set to '' if value from process.env is undefined) to avoid Error TS2322
2932
CURRENT_ENVIRONMENT: fromWorkerEnv ? env.CURRENT_ENVIRONMENT : process.env.CURRENT_ENVIRONMENT || '',
3033
DISCORD_APPLICATION_ID: fromWorkerEnv ? env.DISCORD_APPLICATION_ID : process.env.DISCORD_APPLICATION_ID || '',
3134
DISCORD_GUILD_ID: fromWorkerEnv ? env.DISCORD_GUILD_ID : process.env.DISCORD_GUILD_ID || '',

config/envVarCheck.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import { loadEnv } from "./config";
44
validateEnv();
55

66
/**
7-
* Validate if all the required environment variables defined in the schema above are set
8-
* and are in the correct format else throw an error
7+
* Validate if all the required environment variables are set to a non empty value
8+
* else throw an error
99
* ---
1010
*/
1111
export function validateEnv (){
12-
const envLoadedFromProcess: env = loadEnv({}, false);
13-
console.log(envLoadedFromProcess);
14-
const missingEnvVars = Object.keys(envLoadedFromProcess).filter((key) => envLoadedFromProcess[key] == '');
12+
//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((key) => envLoadedFromProcess[key] == '');
1515

16-
// Logging missing environment variables and exit if any are missing
17-
if (missingEnvVars.length > 0) {
18-
throw new Error(`Missing environment variables: ${missingEnvVars.join(', ')}`);
19-
} else {
20-
console.log('All required environment variables are set.');
21-
}
16+
// Logging missing environment variables and throw error if any are missing
17+
if (missingEnvVars.length > 0) {
18+
throw new Error(`Missing environment variables: ${missingEnvVars.join(', ')}`);
19+
} else {
20+
console.log('All required environment variables are set.');
21+
}
2222
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
"ts-jest": "^29.0.5",
3737
"ts-node": "^10.9.1",
3838
"typescript": "^4.9.4",
39-
"wrangler": "^3.1.1",
40-
"zod": "^3.23.8"
39+
"wrangler": "^3.1.1"
4140
},
4241
"dependencies": {
4342
"@tsndr/cloudflare-worker-jwt": "^2.2.1",

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import { generateInviteLink } from "./controllers/generateDiscordInvite";
2222
import { sendProfileBlockedMessage } from "./controllers/profileHandler";
2323
import { sendTaskUpdatesHandler } from "./controllers/taskUpdatesHandler";
2424

25-
import config from "./../config/config";
26-
import { loadEnv } from "./../config/config";
25+
import config,{loadEnv} from "./../config/config";
26+
2727
const router = Router();
2828

2929
router.get("/", async () => {
@@ -107,10 +107,12 @@ export default {
107107
return new JSONResponse(response.BAD_SIGNATURE, { status: 401 });
108108
}
109109
}
110-
return router.handle(request, loadEnv(env,true), ctx);
110+
const envLoadedFromWorker: env = loadEnv(env,true);
111+
return router.handle(request, envLoadedFromWorker, ctx);
111112
},
112113

113114
async scheduled(req: Request, env: env, ctx: ExecutionContext) {
114-
ctx.waitUntil(send(loadEnv(env,true)));
115+
const envLoadedFromWorker: env = loadEnv(env,true);
116+
ctx.waitUntil(send(envLoadedFromWorker));
115117
},
116118
};

0 commit comments

Comments
 (0)