Skip to content

Commit

Permalink
Merge pull request #7 from tclindner/lazy-load
Browse files Browse the repository at this point in the history
Move handlers so they are lazy loaded
  • Loading branch information
marconi1992 authored May 30, 2019
2 parents 1eca102 + 66dee21 commit 149cb90
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ class LambdaOffline {

const { servicePath } = this.serverless.config;
const serviceRuntime = this.service.provider.runtime;
const handlers = Object.keys(this.service.functions).reduce((acc, key) => {

const funOptions = Object.keys(this.service.functions).reduce((acc, key) => {
const fun = this.service.getFunction(key);
const funOptions = functionHelper.getFunctionOptions(fun, key, servicePath, serviceRuntime);
const handler = functionHelper.createHandler(funOptions, {});
acc[key] = handler;
acc[key] = functionHelper.getFunctionOptions(fun, key, servicePath, serviceRuntime);
return acc;
}, {});

Expand All @@ -43,7 +42,13 @@ class LambdaOffline {
const invocationType = req.headers['x-amz-invocation-type'];
const { functionName } = req.params;

const handler = handlers[functionName];
const options = funOptions[functionName];

if (!options) {
return reply().code(404);
}

const handler = functionHelper.createHandler(options, {});

if (!handler) {
return reply().code(404);
Expand Down

0 comments on commit 149cb90

Please sign in to comment.