0

I'm trying to deploy my laravel app with socket.io and I have everything up and running. Node, redis, etc. but when socket event is fired I get this exact error message.

XMLHttpRequest cannot load http://localhost/socket.io/?EIO=3&transport=polling&t=Lbe2fnV. Cross-origin redirection denied by Cross-Origin Resource Sharing policy.

I have gone into my nginx config file and added the following:

upstream app_yourdomain {
    server 127.0.0.1:3000;
    keepalive 8;
}
location ~* \.io {
     proxy_pass http://localhost:3000;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection 'upgrade';
     proxy_set_header Host $host;
     proxy_cache_bypass $http_upgrade; 
}

but it doesn't do anything.

How can I get rid of the cross-orgin error? My biggest success came from this post

NodeJS server on DigitalOcean using socket.io returns connection refused

Community
  • 1
  • 1
wizardzeb
  • 1,546
  • 2
  • 14
  • 30

1 Answers1

0

Try to set the origins property like so.

io.set('origins', 'http://localhost:3000');

You can put in every url you allow to get the request from for example

io.set('origins', 'http://google.com:80');

or allow all

io.set('origins', '*:*');

More about the origin property can be found here

Community
  • 1
  • 1
Jesse de gans
  • 1,432
  • 1
  • 14
  • 27
  • I did that and the error went away, but now it doesn't work. It doesn't give any error messages either. When I'm receiving the socket this is what I'm putting. `var socket = io("http://localhost:3000");` – wizardzeb Jan 04 '17 at 15:33
  • @CriticalTheWizard Try setting the origin property to *:* just for testing purposes? does it work after that or? – Jesse de gans Jan 05 '17 at 09:47
  • i was working on earlier and I found the I had to put `var socket = io("http://mywebsite.com:3000") ` because localhost was actually connecting to my local dev server I had running. My problem now is the website can connect to the socket (that's what the socket debugger says) but it can't receive any data. It keeps writing a ping message, flushes 1 packet, then gets the correct type with data as undefined. – wizardzeb Jan 05 '17 at 15:44
  • That sounds more like a code error can u post your code? Or make a new question? – Jesse de gans Jan 06 '17 at 00:45
  • [new question](http://stackoverflow.com/questions/41497621/laravel-socket-io-production-server-not-receiving-data) – wizardzeb Jan 06 '17 at 01:43