jeremydaly / jeremydaly/lambda-api
Middlewares not being called when using wildcard "*"
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.5k
- Forks
- 127
- Avg merge
- 31m
- Merged PRs (30d)
- 2
Description
Lambda api: 0.10.1
I have this API:
const api = require('lambda-api')({base: 'v2'})
, middleware = require('../utils/middleware')
, LiveblogApi = require('../apis/liveblogApi');
//apply middlewares
api.use(middleware.addCorsHeaders);
api.use(middleware.logRequest);
api.use(['/data/*'], middleware.authorize);
api.use(middleware.populateCommonHeaders);
api.use(middleware.errorHandler);
api.post('/data/pbp/:eventId', async (req, res) => {
let response = await LiveblogApi.addPost(req.params.eventId, req.body);
return res.json(response);
});
api.post('/data/pbp/:eventId/:key', async (req, res) => {
let response = await LiveblogApi.setPost(req.params.eventId, req.params.key, req.body);
return res.json(response);
});
api.delete('/data/pbp/:eventId/:key', async (req, res) => {
let response = await LiveblogApi.deletePost(req.params.eventId, req.params.key);
return res.json(response);
});
api.post('/data/drafts/:eventId', async (req, res) => {
let response = await LiveblogApi.addDraft(req.params.eventId, req.body);
return res.json(response);
});
api.post('/data/drafts/:eventId/:key', async (req, res) => {
let response = await LiveblogApi.setDraft(req.params.eventId, req.params.key, req.body);
return res.json(response);
});
api.delete('/data/drafts/:eventId/:key', async (req, res) => {
let response = await LiveblogApi.deleteDraft(req.params.eventId, req.params.key);
return res.json(response);
});
api.delete('/data/comments/:eventId/:postId/:key', async (req, res) => {
let response = await LiveblogApi.deleteComment(req.params.eventId, req.params.postId, req.params.key);
return res.json(response);
});
module.exports = api;
You can see that I have another JS module that holds all middlewares. When I deploy it like this, it looks like only the authorize middleware is being called.
If I remove the line:
api.use(['/data/*'], middleware.authorize);
Then the other middlewares are called normally.
In old versions of the lib this didn't happen, I just updated to the newest version and deployed again.
My workaround:
api.use(middleware.authorize); which has the same effect as before.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the api.use middleware registrations and the wildcard path handling, using the listed /data/* authorize middleware as the reproduction. Verify how middleware ordering and path matching behave when this registration is present; done means the general middlewares still run and authorize remains scoped to /data/*.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100