Skip to content

Loading…

Allowing connect to be consumed within a parent handler #697

Closed
guybedford opened this Issue · 3 comments

3 participants

@guybedford

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
Sencha Labs member
tj commented

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

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
Sencha Labs member
tj commented

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
Something went wrong with that request. Please try again.