restify / restify/node-restify
Routes and middleware not run in defined order
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 975
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 5
Description
Bug Report
Restify Version
v7.2.1
Node.js Version
v10.5.0
Expected behaviour
In restify v4, using the serveStatic plugin before including any middleware would not run the middleware when serving a file.
Actual behaviour
Middleware is now run prior to serving files.
Repro case
const restify = require('restify');
const errors = require('restify-errors');
const server = restify.createServer();
server.get('/', restify.plugins.serveStatic({
directory : './public/',
default : 'index.html'
}));
server.use((request, response, next) => {
return next(new errors.ForbiddenError('Nope'));
});
server.get('/api/test', (request, response, next) => {
response.send({});
return next();
});
server.listen(8000);
Expected: Request to / serves index.html, request to /api/test gives a ForbiddenError
Actual: Request to both / and /api/test gives a ForbiddenError
Cause
Changes somewhere between v4 and v7, presumably the change in routing/middleware handling.
Are you willing and able to fix this?
No, there appears to be other issues with serveStatic in general so this should be tackled as part of sorting the overall problem out.
Contributor guide
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 with the serveStatic plugin and the routing/middleware handling involved in the supplied reproduction. Verify the behavior on / and /api/test using the listed Restify and Node.js versions, then compare it with the stated Restify v4 behavior. Done means static files bypass the later middleware while API routes still receive it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100