节点。js插座。io get cookie(在服务器上- Debian)

时间:2021-11-14 19:00:07

My script runs well on my computer, but fails on my server (Debian), with Socket.io. When I do:

我的脚本在我的计算机上运行良好,但是在我的服务器(Debian)上失败了。当我做:

io.set('authorization', function (handshake, callback) {
  console.log(handshake.headers);
  callback(null, true);
});

I do get the handshake.headers.cookies (io and session cookies) when running on localhost. But when I run the scripts on my server (some version of node and everything), I only get the "io" cookie, that is not even yet in the browser. Do you have any idea why?

我有手牌。运行在本地主机上的cookie (io和会话cookie)。但是当我在我的服务器上运行脚本(一些版本的节点和所有东西)时,我只获得了“io”cookie,这在浏览器中还没有。你知道为什么吗?

EDIT: the cookies are set in the browser in both cases.

编辑:在这两种情况下,cookie都在浏览器中设置。

1 个解决方案

#1


0  

It was just the way I initialised socket.io, I realised that it worked when going on the IP of the server and not on the domain name. So now I simply do that:

这就是我初始化socket的方式。io,我意识到它是在服务器的IP上工作的,而不是在域名上。现在我就这样做了:

socket = io(window.location.hostname);

#1


0  

It was just the way I initialised socket.io, I realised that it worked when going on the IP of the server and not on the domain name. So now I simply do that:

这就是我初始化socket的方式。io,我意识到它是在服务器的IP上工作的,而不是在域名上。现在我就这样做了:

socket = io(window.location.hostname);