Browse Source

Merge pull request #65 from petemill/run-envvars

Support environment variables on 'run'
master
Nicola Peduzzi 8 years ago
committed by GitHub
parent
commit
4c6b344596
  1. 11
      lib/run.js

11
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;
@ -44,6 +46,14 @@ module.exports = {
};
},
setEnvironmentVars(functionName) {
const providerEnvVars = this.serverless.service.provider.environment || {};
const functionEnvVars = this.serverless.service.functions[functionName].environment || {};
Object.assign(process.env, providerEnvVars, functionEnvVars);
console.log('core', process.env.NODE_ENV);
},
run(stats) {
const functionName = this.options.function;
@ -80,6 +90,7 @@ module.exports = {
const handler = this.loadHandler(stats, functionName, true);
const event = this.getEvent();
const context = this.getContext(functionName);
handler(
event,
context,

Loading…
Cancel
Save