express 的 IP 绑定 - CNode技术社区

express 的 IP 绑定
发布于 12 年前 作者 xianggp 13795 次浏览 最后一次编辑是 9 年前

express 的IP绑定时怎么绑的啊? 好像只看到

var app = express();
http.createServer(app).listen(app.get('port'),function(){
 console.log('listening ....');
});

原生的如下:

http.createServer(function(req,res){
 res.writeHead(200,{'Content-Type':'text/plain'});
 res.end('hello world');
}).listen(1337,'127.0.0.1');
2 回复

如果原生代码是这个

http.createServer(function(req,res){
 res.writeHead(200,{'Content-Type':'text/plain'});
 res.end('hello world');
}).listen(1337,'127.0.0.1');

那么用express可以这么写

var app = express();
http.createServer(app).listen('1337','127.0.0.1');
app.get('/', function(req, res){
 res.set('Content-Type', 'text/plain');
 res.send('hello world');
});

谢谢

回到顶部

AltStyle によって変換されたページ (->オリジナル) /