A
A
Andrei2582022-02-08 18:18:35
Node.js
Andrei258, 2022-02-08 18:18:35

How to set up cors in larave + node.js?

I have a site on laravel and on it websockets (node.js)

Server.js

var io = require('socket.io')(6001);
io.on('connection', function(socket){
  console.log('New Connection!');
})


The client side keeps giving the following error:
var socket = io(':6001');

Access to XMLHttpRequest at 'http://myapp:6001/socket.io/?EIO=4&transport=polling&t=NxPwAZS' from origin 'http://myapp' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrei258, 2022-02-08
@Andrei258

Fixed like this

var socket = io('http://myapp:6001', { transports : ['websocket'] });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question