I'm using socket.io to make a realtime chat app. Almost all api works except socket.
My console shows
Access to XMLHttpRequest at 'https://example-server.vercel.app/socket.io/?EIO=4&transport=polling&t=OVLsA1y&sid=GaWraRTVn-d2od-LAAAC' from origin 'https://example.vercel.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
this is my code at:
client:
const socket = io("https://example-server.vercel.app", {withCredentials: true,}).connect();
server:
const io = new Server(server, {
cors: {
origin: true,
credentials: true,
methods: ["GET", "POST"],
allowedHeaders: ["my-custom-header"],
exposedHeaders: ["my-custom-header"],
},
allowEIO3: true,
});
I have tried the ways from the links that have been helped like: https://stackoverflow.com/questions/24058157/socket-io-node-js-cross-origin-request-blocked,https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe
but it not working with me.Thanks for your help!
More information: when i running at localhost it work