Skip to content

Commit

Permalink
refactor: global envManager instead of envMap
Browse files Browse the repository at this point in the history
  • Loading branch information
amithm7 committed Dec 17, 2021
1 parent 3836a27 commit c160c7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ import * as log from "./helpers/log.js";
import * as util from "./helpers/util.js";
import * as dnsutil from "./helpers/dnsutil.js";

const envManager = new EnvManager();
globalThis.envMap = envManager.getMap();
globalThis.envManager = new EnvManager();

if (typeof addEventListener !== "undefined") {
addEventListener("fetch", (event) => {
if (!envManager.isLoaded) {
envManager.loadEnv();
}
event.respondWith(handleRequest(event));
});
}

export function handleRequest(event) {
if (!envManager.isLoaded) {
envManager.loadEnv();
}
const processingTimeout = envManager.get("workerTimeout");
const respectTimeout =
envManager.get("runTimeEnv") == "worker" && processingTimeout > 0;
Expand Down Expand Up @@ -53,10 +52,6 @@ async function proxyRequest(event) {
return res;
}

// For environments which don't use FetchEvent to handle request.
if (!envManager.isLoaded) {
envManager.loadEnv();
}
const currentRequest = new CurrentRequest();
const plugin = new RethinkPlugin(event);
await plugin.executePlugin(currentRequest);
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class RethinkPlugin {
/**
* Parameters of RethinkPlugin which may be used by individual plugins.
*/
this.parameter = new Map(envMap);
this.parameter = new Map(envManager.getMap());
this.registerParameter("request", event.request);
this.registerParameter("event", event);
this.registerParameter(
Expand Down

0 comments on commit c160c7a

Please sign in to comment.