Filtered middleware never run
See original GitHub issueHi there,
I’m trying to replace Express with Polka in a small project, and I’m facing an issue where a “filtered” middleware is never run :
const polka = require('polka');
const serveStatic = require('serve-static');
/*
*
*/
const app = polka();
// Always run, as expected
app.use((req, res, next) => {
console.log(req.method, req.url);
next();
});
// Never run, but I expect it to be when navigating to /admin/**/*
app.use('/admin', (req, res, next) => {
console.log(' @admin!');
next();
});
// Always run, as expected
app.use(serveStatic(__dirname + '/_static'));
/*
*
*/
app.listen(4444, () => console.log('Listening on port 4444...'));
It’s probably a very silly error but I don’t see what I’m doing wrong here.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
couldn't filter request through middleware - Stack Overflow
I am trying to filter my http request by using middleware. I want to check if the "friends_id" that i am getting from...
Read more >Is it possible to have an EF Core middleware or something that can ...
I'm trying to apply a particular filter logic to my queries based on some parameters that will be different for every user. So,...
Read more >Conditional Middleware based on request in ASP.NET Core
This post looks at how to configure ASP.NET Core middleware in a way that allows you to have different middleware for different types...
Read more >Defining middleware | LoopBack Documentation
initial - The first point at which middleware can run. ... the response chain, the “catch-all” middleware is never triggered when a get...
Read more >How to Write Middleware for Express.js Apps - Stormpath
In other frameworks “middleware” is called “filters”, ... As you write your own middleware you will run into some pitfalls, but fear not!...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok. Thank you!
I would fix it by moving serve-static to its own path. Most of the time, you don’t need it running globally (it’s slow and induces a significant performance hit too).
Maybe something like this:
Polkadot doesn’t have a router or middleware runner built in, so you would/could arrange it however you’d like! It’s not affected by anything in Polka, no 😃
There is a
polka@next
release out btw. It has the ordering changes so it might feel more comfortable/familiar to you