Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware does not work for a filter #48

Open
titovanton opened this issue Jun 6, 2017 · 1 comment
Open

Middleware does not work for a filter #48

titovanton opened this issue Jun 6, 2017 · 1 comment

Comments

@titovanton
Copy link

The problem is even deeper than i've described in the caption. Lets say i have this code:

const get = Picker.filter(function(req, res) {
  return req.method == 'GET';
});
const post = Picker.filter(function(req, res) {
  return req.method == 'POST';
});

// Hello there, you have no documentation provided about custom middleware, but it's ok, i can use google
const someMiddleware = (req, res, next) => {
  console.log('see this on any route, lol');
  next();
}

// i would use the middleware only for POST requests, so i suppose i should write this way:
post.middleware(someMiddleware);

// no, u didn't get it, i even expect the middleware is gonna be run only for this route: /api/items/
// just notice: why did u splited out the params from the req object? The Express does not, so it makes some mess, when i want to assign some URL/HEADER/BODY encoded parameters to some local variable, but the word "params" is already busy
post.route('/api/items/', callback);

// and lets say i want to provide some SEO markup for google/tweeter/blablaElse bots with this one:
const seo = Picker.filter(function(req, res) {
  return req.method == 'GET';
});

seo.get('/', seoCallback);

Ok, what do we have? Unexpected behavior for a normal mind flow:
'see this on any route, lol' - u will see this on every request, does not metter, did u come to '/', or '/api/items' with POST header. Filter also does not make effect on a decision to launch or not to launch a middleware. So all code above makes absolutly NO sense! You can not validate some header encoded parameter, with redirect on fail or next() on success, in middleware for specific route of a specific filter.

@titovanton
Copy link
Author

titovanton commented Jun 6, 2017

Don't get me wrong and I'm sorry if I'm too hard. But it peaces me off, when I'm understanding, that your code applies the multer(npm middleware) for EVERY ROUTE in the app!!! Even if it should be handled on a client side...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant