NodeJS 如何获取Connect服务器的主机名和端口号?

mpgws1up  于 2023-05-28  发布在  Node.js
关注(0)|答案(2)|浏览(170)

this question for Express类似,是否有一种编程方式来获取正在运行的Connect服务器的主机名和端口号?

cxfofazt

cxfofazt1#

很简单

var http = require('http');
var connect = require('connect');
var app = connect().use(connect.static(__dirname)); //or any other use
var server = http.createServer(app).listen(port, host, callback);
w8f9ii69

w8f9ii692#

想明白了

var connect = require("connect");
var server = require("http").createServer(connect());
server.listen(function() {
  console.log(server.address()); // Print host name and port number.
});

相关问题