How I can handle CORS on client-side
See original GitHub issueI have a problem with connection to my server, which located at localhost:8080
I got the error with followeing message:
Access to XMLHttpRequest at 'http://localhost:3000/socket.io/?EIO=3&transport=polling&t=NO51tSB' from origin 'http://localhost:8080' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
Server-side code:
const io = require("socket.io")(http, { cors: { origin: "http://localhost:8080", methods: ["GET", "POST"] } });
Client-side code:
Vue.use(new VueSocketIO({ debug: true, connection: '//localhost:3000/', }))
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:12
i had this same issue but i solved it by following these steps
1=> in server side code update your connection and allow cors origin to *
2 => Instead of connection string you must provide socket.io connection object
Hope this works for you as well
Thank’s a lot)