Augment LambdaServer to use URL path parameter from request to lookup #366
Conversation
1 similar comment
It's a good question on the separator - I believe the dot is the standard for Lambdas (at least Node.js ones): Otherwise, looking great. And FYI, we changed around the build process to make it easier to handle external pull requests. Now all PRs are run with Travis/Coveralls without any environment variables. Once pulled in, they are run in Circle with full environment variables and more complete test coverage. |
I'll change it to use the '.' and also update the validation to error if more than one . is present in the path (aws will fail to execute a lambda with more than one '.' in its path so we might as well be compatible with that behavior here too) |
lib/client/lambda-server.ts
Outdated
@@ -107,7 +121,7 @@ export class LambdaServer { | |||
console.log(JSON.stringify(bodyJSON, null, 2)); | |||
} | |||
|
|||
const handlerFunction = this.functionName ? this.functionName : "handler"; | |||
handlerFunction = handlerFunction != null ? handlerFunction : this.functionName ? this.functionName : "handler"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend going with
handlerFunction = handlerFunction ? handlerFunction : ...
To include undefined apart from null, right now it's undefined if request.url is "/"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(undefined != null) is false though thanks to single '=' in javascript's single != comparison operator ... so I believe the above should work as desired when handlerFunction is either null or undefined.
I changed it though as the your version is prettier and works too (except when supplied 'falsey' values which doesn't matter here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change
module information when path information is supplied in url
…er than ':' Change spelling of handlerFunction comparison logic
module information when path information is supplied in url.
Towards closing #334
Not specifically mentioned in the discussion on the issue -- was the question of how to encode the module and handler names in the url. In this PR I interpret the ":" character as a special character to separate module path from handler -- I believe ':''s are not allowed in node paths ...?
That may not be the 'right way' though -- serverless config file uses a '.' format which I personally find to be a pretty bad choice -- maybe using that convention would be better here ... example code in use in various bst context's uses path/to/SomeFunction.js as the module representation though and I was worried about compatibility if I tried to use '.' as the path/handler separator ...