node.js - nodejs express如何获取服务器IP和端口?
天蓬老师
天蓬老师 2017-04-17 15:24:09
0
2
1023

我们的网址中常用<base href="">来标明前面那部分,然而,nodejs express框架有这个方法吗?是不是要手动写一个拦截器?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
黄舟
  • What are you trying to intercept? Your node express should not be a server, listening for requests. The requests are all sent to your server. Do you know your own IP and port? ? ?

const server = app.listen(3000, 'localhost', function () {
  const host = server.address().address
  const port = server.address().port
  console.log("应用实例,访问地址为 http://%s:%s", host, port)
})
大家讲道理
var ip = req.headers['x-real-ip'] ? req.headers['x-real-ip'] : req.ip.replace(/::ffff:/, '');

The IP obtained above has been processed. You can get the IP regardless of whether you use a proxy or a direct connection.

Port. . . It seems I haven’t found a way

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template