Skip to content

Commit 4da8a76

Browse files
committed
wip
1 parent a6dc6b1 commit 4da8a76

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
@@ -149,6 +149,7 @@ class API {
149149

150150
// Make a local copy of routes
151151
let routes = this._routes;
152+
// console.log('routes', JSON.stringify(routes));
152153

153154
// Create a local stack for inheritance
154155
let _stack = { '*': [], m: [] };
@@ -477,6 +478,7 @@ class API {
477478
this.METHOD('__MW__', route, ...middleware);
478479
});
479480
}
481+
480482
} // end use
481483

482484
// Finally handler

0 commit comments

Comments
 (0)