Skip to content

Commit eba0fe4

Browse files
authored
Merge pull request dherault#254 from guillaume/fix-process-env-functions
Assign process.env per function calls.
2 parents 14bfcd0 + 7489d60 commit eba0fe4

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/index.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class Offline {
185185

186186
// Methods
187187
this._setOptions(); // Will create meaningful options from cli options
188-
this._setEnvironment(); // will set environment variables from serverless.yml file
188+
this._storeOriginalEnvironment(); // stores the original process.env for assigning upon invoking the handlers
189189
this._registerBabel(); // Support for ES6
190190
this._createServer(); // Hapijs boot
191191
this._createRoutes(); // API Gateway emulation
@@ -194,16 +194,8 @@ class Offline {
194194
return this.server;
195195
}
196196

197-
_setEnvironment() {
198-
if (this.options.noEnvironment) return;
199-
200-
Object.assign(process.env, this.service.provider.environment || {});
201-
202-
const _this = this;
203-
204-
Object.keys(this.service.functions).forEach(functionName => {
205-
Object.assign(process.env, _this.service.functions[functionName].environment || {});
206-
});
197+
_storeOriginalEnvironment() {
198+
this.originalEnvironment = _.extend({}, process.env);
207199
}
208200

209201
_setOptions() {
@@ -460,6 +452,7 @@ class Offline {
460452
let handler; // The lambda function
461453

462454
try {
455+
process.env = _.extend({}, this.service.provider.environment, this.service.functions[key].environment, this.originalEnvironment);
463456
handler = functionHelper.createHandler(funOptions, this.options);
464457
}
465458
catch (err) {

0 commit comments

Comments
 (0)