Skip to content

Commit

Permalink
v0.1.3: trailling slash issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dherault committed Feb 19, 2016
1 parent 42fd6e9 commit c350378
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See [Credits and inspiration](https://github.com/dherault/serverless-offline#cre

### Installation

Requires Node v4 and over. In your Serverless project:
Requires Node v4 and over and [Serverless](https://github.com/serverless/serverless) v0.4.x. In your Serverless project:

```
npm install serverless-offline
Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ module.exports = function(ServerlessPlugin, serverlessPath) {

_createServer() {

this.server = new Hapi.Server();
this.server = new Hapi.Server({
connections: {
router: {
stripTrailingSlash: true // removes trailing slashes on incoming paths.
}
}
});
this.port = this.evt.port || 3000;

this.server.connection({
Expand Down Expand Up @@ -76,7 +82,10 @@ module.exports = function(ServerlessPlugin, serverlessPath) {

const method = endpoint.method;
const epath = endpoint.path;
const path = this.prefix + (epath.startsWith('/') ? epath.slice(1) : epath);

// Prefix must start and end with '/' BUT path must not end with '/'
let path = this.prefix + (epath.startsWith('/') ? epath.slice(1) : epath);
if (path.endsWith('/')) path = path.slice(0, -1);

SCli.log(`Route: ${method} ${path}`);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-offline",
"version": "0.1.2",
"version": "0.1.3",
"description": "Simulates your API Gateway ressources locally to call your lambda functions offline",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit c350378

Please sign in to comment.