connect icon indicating copy to clipboard operation
connect copied to clipboard

Shouldn't Server.prototype.listen accept a callback like node's?

Open publickeating opened this issue 16 years ago • 4 comments

I'm guessing that the callback in node's .listen() is a recent addition and therefore not yet in connect?

Thanks.

publickeating avatar Sep 06 '10 04:09 publickeating

What's the code you're trying? Connect's Server is a subclass of Node's HTTP server, and doesn't even touch the listen function itself (I'm pretty sure, haven't quite checked). I'm using a listen callback in nTunes (in bin/nTunes).

This should work:

var connect = require("connect");
connect.createServer(
  connect.staticProvider(__dirname)
).listen(80, function() {
  console.log("Port binded!");
})

TooTallNate avatar Sep 07 '10 02:09 TooTallNate

Connect's Server .listen() only accepts two arguments, but node's accepts three. The third being an optional hostname (otherwise the server listens on any IP). When I was passing a callback as a second argument, like you are, it works as you show, but I also want to prevent access on an internal IP address (hence bind to the external one only).

Ex. var app = connect.createServer(); app.listen(80, 'myapp.com', function() { console.log("... and ready!"); });

publickeating avatar Sep 07 '10 03:09 publickeating

See if 14dc8dc11cb7ff0b1fc8892f7c5810a1137f637f fixes your issue.

creationix avatar Sep 07 '10 19:09 creationix

Thanks!

publickeating avatar Sep 07 '10 21:09 publickeating