开发者

Forward get request from one node.js server to another

I currently have two instances of nodejs servers running, both listening on localhost, with instance 1 on port 15000 and instance 2 on port 16000. The first is going t开发者_开发百科o work as a master with the second as part of a group of slaves, where any request coming into the first gets forwarded to the second.

I'm having trouble sending any messages from the first to the second.

var jquery = require('jquery');  
jquery.get('http://localhost:16000');

called from the first does not get received by the second (jquery is loaded correctly). I'm about to try Mootools, but would like some advice on the best way to forward an incoming nodejs request directly to another instance of a nodejs server.


You want cluster.

You simply call cluster with an instance of a http.Server or net.Server and it does the load balancing for you.

If you want to roll out something yourself then call your clients with http.request which is a sensible way to send a HTTP request to a particular server in node.js.

Using jQuery or MooTools to do this for you is horrible (They don't use native C goodness, like standard node.js modules do!). Don't do this. The only reason why you would want jQuery / MooTools in node is to manipulate jsdom

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜