Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Load all environment vars before trying to require any files. #101

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ module.exports = {
if (purge) {
utils.purgeCache(handlerFilePath);
}
//set environment before requiring, as imported modules will be immediately
this.setEnvironmentVars(functionId);
const module = require(handlerFilePath);
const functionObjectPath = handler.slice(1);
let func = module;
Expand Down
6 changes: 6 additions & 0 deletions lib/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module.exports = {
throw err;
}
const loadedModules = [];
// We need to set all environments before requiring any handlers, as
// imported modules may be in a single file and immediately require
// their environment.
for (let funcConf of funcConfs) {
this.setEnvironmentVars(funcConf.id);
}
for (let funcConf of funcConfs) {
funcConf.handlerFunc = this.loadHandler(
stats,
Expand Down