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 used as middleware #701

Merged
merged 3 commits into from Jan 13, 2013
Merged

Allowing connect to be used as middleware #701

merged 3 commits into from Jan 13, 2013

Conversation

guybedford
Copy link
Contributor

As in #697.

Let me know if you would like a test case as well.

This allows me to write the following code:

  var connect = require('connect'),
    http = require('http');

var myHandler = my_async_handler_generator();
var connectHandler = connect();

myHandler.on(function(req, res, next) {
  console.log('This handler comes before anything else');
  next();
});

myHandler.on(connectHandler);

myHandler.on(function(req, res, next) {
  res.writeHead(200, {
    'Content-Type': 'text/plain'
  });
  res.end('This is the next fall through after the connect handlers');
});

http.createServer(myHandler).listen(8080);

@tj
Copy link
Member

tj commented Dec 6, 2012

test case would be good thanks

@guybedford
Copy link
Contributor Author

I've added in a test case for this. I've included it in server.js, but it may make more sense as a separate file.

@guybedford
Copy link
Contributor Author

It seems that the Travis build test doesn't like the following:

  http.get('http://localhost:5556/', function(res){
    //...
  });

The test was working fine on my localhost, suggestions on getting this working welcome.

@gregrperkins
Copy link

Failing in node.js 0.6.21, per https://travis-ci.org/senchalabs/connect/jobs/3694390 .

This is because node's interface of http.get() changed from 0.6 to 0.8, per https://github.com/joyent/node/wiki/API-changes-between-v0.6-and-v0.8

See also:
http://nodejs.org/docs/v0.6.21/api/http.html#http_http_get_options_callback
http://nodejs.org/api/http.html#http_http_get_options_callback

Try replacing that line with:

      http.get({
        host: 'localhost',
        port: 5556,
        path: '/'
      }, function(res){

@guybedford
Copy link
Contributor Author

Thanks very much for the suggestion - I've added this in.

@guybedford
Copy link
Contributor Author

Just checking if this needs any further discussion or changes?

tj added a commit that referenced this pull request Jan 13, 2013
Allowing connect to be used as middleware
@tj tj merged commit 6ed44ac into senchalabs:master Jan 13, 2013
@guybedford
Copy link
Contributor Author

Sweet, thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants