Skip to content

Commit 26a3e83

Browse files
authored
Merge pull request #9 from jeremydaly/v0.1.1
v0.1.1
2 parents 7579ee3 + 37ab326 commit 26a3e83

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ api.use(function(req,res,next) {
248248

249249
The `next()` callback tells the system to continue executing. If this is not called then the system will hang and eventually timeout unless another request ending call such as `error` is called. You can define as many middleware functions as you want. They will execute serially and synchronously in the order in which they are defined.
250250

251-
### Clean Up
251+
## Clean Up
252252
The API has a built-in clean up method called 'finally()' that will execute after all middleware and routes have been completed, but before execution is complete. This can be used to close database connections or to perform other clean up functions. A clean up function can be defined using the `finally` method and requires a function with two parameters for the REQUEST and the RESPONSE as its only argument. For example:
253253

254254
```javascript

Diff for: request.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class REQUEST {
4141
}
4242
}
4343

44-
// Extract path from event
45-
let path = app._event.path.trim().replace(/^\/(.*?)(\/)*$/,'$1').split('/')
44+
// Extract path from event (strip querystring just in case)
45+
let path = app._event.path.trim().split('?')[0].replace(/^\/(.*?)(\/)*$/,'$1').split('/')
4646

4747
// Remove base if it exists
4848
if (app._base && app._base === path[0]) {

Diff for: test/routes.js

+23
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,29 @@ describe('Route Tests:', function() {
200200
}) // end it
201201

202202

203+
it('Event path + querystring w/ trailing slash (this shouldn\'t happen with API Gateway)', function() {
204+
let _event = Object.assign({},event,{ path: '/test/123/query/?test=321', queryStringParameters: { test: '321' } })
205+
206+
return new Promise((resolve,reject) => {
207+
api.run(_event,{},function(err,res) { resolve(res) })
208+
}).then((result) => {
209+
//console.log(result);
210+
expect(result).to.deep.equal({ headers: { 'Content-Type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok","param":"123","query":"321"}' })
211+
})
212+
}) // end it
213+
214+
it('Event path + querystring w/o trailing slash (this shouldn\'t happen with API Gateway)', function() {
215+
let _event = Object.assign({},event,{ path: '/test/123/query?test=321', queryStringParameters: { test: '321' } })
216+
217+
return new Promise((resolve,reject) => {
218+
api.run(_event,{},function(err,res) { resolve(res) })
219+
}).then((result) => {
220+
//console.log(result);
221+
expect(result).to.deep.equal({ headers: { 'Content-Type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok","param":"123","query":"321"}' })
222+
})
223+
}) // end it
224+
225+
203226
it('Missing path: /not_found', function() {
204227
let _event = Object.assign({},event,{ path: '/not_found' })
205228

0 commit comments

Comments
 (0)