在 node.js Express 中获取当前请求的主机名 [英] Get hostname of current request in node.js Express
本文介绍了在 node.js Express 中获取当前请求的主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我可能在这里遗漏了一些简单的东西,但我似乎无法找到一种方法来获取我正在向其发送响应的请求对象所请求的主机名.
So, I may be missing something simple here, but I can't seem to find a way to get the hostname that a request object I'm sending a response to was requested from.
是否可以从 node.js 中找出用户当前正在访问的主机名?
Is it possible to figure out what hostname the user is currently visiting from node.js?
推荐答案
如果您在谈论 HTTP 请求,您可以在以下位置找到请求主机:
If you're talking about an HTTP request, you can find the request host in:
request.headers.host
但这依赖于传入的请求.
But that relies on an incoming request.
更多见 http://nodejs.org/docs/v0.4.12/api/http.html#http.ServerRequest
如果您正在寻找机器/本机信息,请尝试进程对象.
If you're looking for machine/native information, try the process object.
这篇关于在 node.js Express 中获取当前请求的主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文