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

Allowing connect to be consumed within a parent handler #697

Closed
guybedford opened this issue Nov 29, 2012 · 3 comments
Closed

Allowing connect to be consumed within a parent handler #697

guybedford opened this issue Nov 29, 2012 · 3 comments

Comments

@guybedford
Copy link
Contributor

This is related to #646

If I don't want to use the connect server handler, but instead provide my own, I have to include the following hack to make connect work:

  var handler = handler_function_generator();
  handler.on(function(req, res, next) {
    req.originalUrl = req.url;
    next();
  });

  handler.on(connect.cookieParser());
  // etc now I can use middleware

This is ok, but it would be great if the hack wasn't necessary. Or even if the following could work:

  var handler = handler_function_generator();

  var connectHandler = connect();

  handler.on(connectHandler);

The issue with the above being that the connect() handler will never fire the next function as it doesn't expect to be used this way.

It would be really great if connect could easily be used in other frameworks in some form like the above, without feeling too hacky. It provides the most solid foundations for a node app at the moment, so it would be great if it could be used in more scenarios like this.

@tj
Copy link
Member

tj commented Dec 6, 2012

well the connect app function is designed for node's http.Server, not what other frameworks may be doing, not everything uses a "next" callback

@guybedford
Copy link
Contributor Author

As a library that pushes the ideas of middleware so nicely, it just feels like it should be possible to use as middleware itself. It shouldn't be more than a line or two to add the callback, and it would really help getting it to work with the framework I've been using. Completely understand if it somehow conflicts with the design goals though. Happy to submit a pull request and test case as well if it helps?

@tj
Copy link
Member

tj commented Dec 6, 2012

you can use them as middleware, though special-cased currently https://github.com/senchalabs/connect/blob/master/lib/proto.js#L69. I'd be happy to look at a pull-request

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

3 participants