Browse Source

set process.env before requiring function handler

master
Pete Miller 8 years ago
committed by GitHub
parent
commit
0541c40363
  1. 5
      lib/run.js

5
lib/run.js

@ -16,6 +16,8 @@ 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;
@ -49,6 +51,7 @@ module.exports = {
const functionEnvVars = this.serverless.service.functions[functionName].environment || {};
Object.assign(process.env, providerEnvVars, functionEnvVars);
console.log('core', process.env.NODE_ENV);
},
run(stats) {
@ -59,7 +62,6 @@ module.exports = {
const handler = this.loadHandler(stats, functionName);
const event = this.getEvent();
const context = this.getContext(functionName);
this.setEnvironmentVars(functionName);
return new BbPromise((resolve, reject) => handler(
event,
@ -88,7 +90,6 @@ module.exports = {
const handler = this.loadHandler(stats, functionName, true);
const event = this.getEvent();
const context = this.getContext(functionName);
this.setEnvironmentVars(functionName);
handler(
event,

Loading…
Cancel
Save