0
I have an API with a running socket.io instance, configured as follows:
const sock = socketIo(server /* servidor express */, {
origins: [CONFIG.frontend /* variavel que contem a url do front */],
handlePreflightRequest: (_req: any, res: ServerResponse) => {
origins: [CONFIG.frontend],
handlePreflightRequest: (_req: any, res: ServerResponse) => {
res.setHeader("Access-Control-Allow-Origin", CONFIG.frontend);
res.writeHead(200, {
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers":"cf-connecting-ip,cf-ipcountry,cf-ray,cf-visitor,x-auth-token,x-forwarded-for,x-forwarded-proto",
});
res.end();
},
},
});
sock.origins(CONFIG.frontend);
And this setting works in local environment (front: localhost:3000, api: localhost:3001)
However, in production (front: sub.dominio.com, api: api.dominio.com), it gives the error: No 'Access-Control-Allow-Origin' header is present on the requested resource
Only in production this error occurs, how can I correct?
(deploy is made using Docker)
Edit: The header goes in the request of options, it fails when it actually connects to the socket, follows a photo of the error: