在node.js Express中获取当前请求的主机名 [英] Get hostname of current request in node.js Express

查看:121
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆