var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
So,if I wanna listen to 192.168.1.100,just like this?
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, '127.0.0.1').listen(80,'192.168.1.100');
Try this
var http = require('http');
function handler(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
};
http.createServer(handler).listen(80, '127.0.0.1');
http.createServer(handler).listen(80, '192.168.1.100');
// or listen to both instead - thx @FlashThunder
// http.createServer(handler).listen(80);
As http creates socket, you can't assign list of ips to one socket, that's why you need to create separate http objects for every ip, or use 0.0.0.0
(or simply dont define second parameter) to listen on all available ips.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With