Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
naorpeled committed Aug 3, 2024
1 parent a6dc6b1 commit 4da8a76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions __tests__/basePath.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ let event = {
}
}

api.use(function (req, res, next) {
console.log('HELLO FROM MIDDLEWARE')
req.testMiddleware = "123";
next();
});

/******************************************************************************/
/*** DEFINE TEST ROUTES ***/
/******************************************************************************/
api.get("/", function(req, res) {
res.status(200).json({
testMiddleware: req.testMiddleware,
})
});

api.get('/test', function(req,res) {
res.status(200).json({ method: 'get', status: 'ok' })
})
Expand All @@ -40,6 +52,12 @@ api.get('/test/test2/test3', function(req,res) {

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

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

it('Simple path with base: /v1/test', async function() {
let _event = Object.assign({},event,{ path: '/v1/test' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class API {

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

// Create a local stack for inheritance
let _stack = { '*': [], m: [] };
Expand Down Expand Up @@ -477,6 +478,7 @@ class API {
this.METHOD('__MW__', route, ...middleware);
});
}

} // end use

// Finally handler
Expand Down

0 comments on commit 4da8a76

Please sign in to comment.