L
L
LIAL2015-01-30 15:26:56
Node.js
LIAL, 2015-01-30 15:26:56

Client interaction error with node.js (Socket.io)?

The bottom line is that a comment pusher is written on the node, everything works fine on the local, on the production the error climbs (I look in the firebug) on ​​the client:

Request from foreign origin blocked: Single origin policy prohibits reading the remote resource on mydomain.com:3000/socket.io/?EIO=3&transport=polli... This can be fixed by moving the resource to the same domain or enabling CORS.

on LAN, this happens when the node crashes, but in this case everything is running.
the node is launched like this: node app.js localhost 3000 (I take the string parameters to start the server later)
on the client: var socket = io(window.location.hostname + ":3000");
..... there is a code for receiving events ....
what is the problem, can someone come across? Is the server configured incorrectly? I did not take into account something when writing that it only works on localhost?
PS: on LAN, the site name is not localhost, but mydomain

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-01-30
@dizballanze

This is because you have socket.io on port 3000 while the site itself is on 80m, which is a CORS violation. To solve the problem, you can use one of two methods:

  • Use the same http server instance as the main application, for example if you are using Express.
  • Proxy socket.io with nginx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question