Exressjs:如何获取https服务器地址和端口?

时间:2016-06-20 10:40:14

标签: node.js express https

如何使用expressjs获取https服务器地址和端口?

使用http:

var server = app.listen(3000, "127.0.0.1", function () {
    var host = server.address().address;
    var port = server.address().port;

    console.log(server.address());
    console.log('Example app listening at http://%s:%s', host, port);
});

结果:

  

{address:'127.0.0.1',family:'IPv4',port:3000}示例应用   在http://127.0.0.1:3000

但是使用https:

https.createServer(options, app).listen(3000, "127.0.0.1", function () {
    console.log('Started!');

    var host = https.address;
    var port = https.port;

    console.log('Example app listening at http://%s:%s', host, port);
});

结果:

Example app listening at http://undefined:undefined

有什么想法吗?

1 个答案:

答案 0 :(得分:-1)