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

notFound handler blocks request to remote service #18

Closed
Flofie opened this issue Dec 13, 2018 · 2 comments
Closed

notFound handler blocks request to remote service #18

Flofie opened this issue Dec 13, 2018 · 2 comments

Comments

@Flofie
Copy link

Flofie commented Dec 13, 2018

If you activate the default express.notFound() handler of feathers this handler blocks the request to the remote services. You alway get a 404.
You could just remove the notFound Handler but the problem with that is that you then get a 404 and a html page returned. Since my client only accepts json we had a problem.

Here is my solution:

// Configure a middleware for 404s and the error handler
app.use((req, res, next) => {
  if (app._router.stack.find(r => r.route && r.route.path && r.route.path === req.path)) {
    next();
  } else {
    const { url } = req;
    const message = `Page not found${process.env.NODE_ENV !== 'production' ? ': ' + url : ''}`;
    next(new NotFound(message, { url }));
  }
});
app.use(errorHandler);

Hope that helps.

@claustres
Copy link
Member

Duplicate of #3 ? Maybe you should push your solution there.

@Flofie
Copy link
Author

Flofie commented Dec 13, 2018

good idea. Did that.

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

2 participants