Skip to content

Commit d952612

Browse files
committed
wip
1 parent ec07a57 commit d952612

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

__tests__/basePath.unit.js

+18
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,21 @@ let event = {
1717
}
1818
}
1919

20+
api.use(function (req, res, next) {
21+
console.log('HELLO FROM MIDDLEWARE')
22+
req.testMiddleware = "123";
23+
next();
24+
});
25+
2026
/******************************************************************************/
2127
/*** DEFINE TEST ROUTES ***/
2228
/******************************************************************************/
29+
api.get("/", function(req, res) {
30+
res.status(200).json({
31+
testMiddleware: req.testMiddleware,
32+
})
33+
});
34+
2335
api.get('/test', function(req,res) {
2436
res.status(200).json({ method: 'get', status: 'ok' })
2537
})
@@ -40,6 +52,12 @@ api.get('/test/test2/test3', function(req,res) {
4052

4153
describe('Base Path Tests:', function() {
4254

55+
it('should return testMiddleware: 123 when calling the root path', async function() {
56+
let _event = Object.assign({},event,{ path: '/v1' })
57+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
58+
expect(result).toEqual({ multiValueHeaders: { 'content-type': ['application/json'] }, statusCode: 200, body: '{"method":"get","status":"ok"}', isBase64Encoded: false })
59+
})
60+
4361
it('Simple path with base: /v1/test', async function() {
4462
let _event = Object.assign({},event,{ path: '/v1/test' })
4563
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class API {
143143

144144
// Make a local copy of routes
145145
let routes = this._routes;
146+
// console.log('routes', JSON.stringify(routes));
146147

147148
// Create a local stack for inheritance
148149
let _stack = { '*': [], m: [] };
@@ -471,6 +472,7 @@ class API {
471472
this.METHOD('__MW__', route, ...middleware);
472473
});
473474
}
475+
474476
} // end use
475477

476478
// Finally handler

0 commit comments

Comments
 (0)