Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 当使用socket.io和static index.html时,如何从远程域获取referer URL_Node.js_Http_Express_Socket.io - Fatal编程技术网

Node.js 当使用socket.io和static index.html时,如何从远程域获取referer URL

Node.js 当使用socket.io和static index.html时,如何从远程域获取referer URL,node.js,http,express,socket.io,Node.js,Http,Express,Socket.io,假设我的站点在index.html中创建了socket.io连接https://example_A.com/mysockets/index.html,以及一个远程网站https://example_B.com/somerandomwebpage 有一个链接到我的网站 如何获取远程推荐人的URL 我发现了这一点,即使用以下内容: io.on('connection', function (socket) { var referer = socket.request.headers.refe

假设我的站点在index.html中创建了socket.io连接https://example_A.com/mysockets/index.html,以及一个远程网站https://example_B.com/somerandomwebpage 有一个链接到我的网站

如何获取远程推荐人的URL

我发现了这一点,即使用以下内容:

io.on('connection', function (socket) {
    var referer = socket.request.headers.referer;
}
但是,这只返回我自己的服务器的URL,该服务器使用express提供index.html。自从https://example_A.com/mysockets/index.html 正在使用io.on连接到套接字,有理由推荐人将是我自己的站点


如何获取远程推荐人的URL而不是我自己的URL?

我在问题中回答了我自己的问题,但没有意识到。。由于express正在提供index.html,因此我需要在express中使用以下内容获取推荐人:

req.header('Referer');