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

How to get a matched route to fallthrought to the next middleware? #35

Closed
RonaldTreur opened this issue Aug 24, 2016 · 3 comments
Closed

Comments

@RonaldTreur
Copy link

When I do something like:

rest.get('/person/:id', function(req, res, next) {
    const toUrl = req.url.replace(rest.context, rest.options.forward);
    req.url = toUrl;
    next();
});

The code is not really that important, it's all about the next-call at the end.

I expect the next (connect) middleware to be invoked, but that never happens. I'm guessing connect-rest does something to block this functionality by wrapping connect's next-callback in their own.

How would I get connect-rest to match and then fall through to the next layer of middleware?

@RonaldTreur RonaldTreur changed the title How to get a matched route to fallthrought to the next middleware How to get a matched route to fallthrought to the next middleware? Aug 24, 2016
@imrefazekas
Copy link
Owner

imrefazekas commented Aug 24, 2016

Dear Ronald,

As I tried to describe here: https://github.com/imrefazekas/connect-rest#rest-functions
connect-rest is not a "middleware-only" solution. How it works:
matches the call against all paths defined by the developer and if nothing matches that next function will be called automatically. In case of matching, your matching service-like function or functions will be called.

You can have multiple service functions to the same path or a wide range of options (please check documentation for details) to orchestrate your business logic as you wish. But as you observed, connect-rest does not follow the path of "middlewares", it serves a different purpose and aim.

I'm sure, you find your voice with connect-rest but if not, lots of REST solutions are built to be a "middleware" only.

@RonaldTreur
Copy link
Author

I know it currently doesn't work that way, but I'm not sure why you would not want to make it pure middleware? I'm also not sure what you mean by "middleware-only". It is connect middleware right? It says so everywhere in the readme.

I actually made a few changes to your code that makes everything work correctly. It might break some other functionality I am not aware of however, I'm not 100% sure.
If you want I can make a PR and you can take a look.

@imrefazekas
Copy link
Owner

imrefazekas commented Aug 29, 2016

Simple aim. To free the business logic from the signature of underlaying layers.
If you combine connect-rest with other libraries, you can write your business logic functions once and can use them in a REST or Websocket or message bus calls without any changes or wrapping and without carrying about the signatures of different libraries. I write many enterprise apps servicing through different interfaces...
That is the reason why I wrote connect-rest, otherwise it would be just another feature-full REST library.
I believe express and restify are doing a great job on that road you are seeking.

Feel free to fork connect-rest if you want to mutate it down to connect-level.

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