Response Headers got cleared after deployment

i have set some headers from code these are set there but after deployment headers not coming and getting cors error because headers are not set

Code=>

app.use((req, res, next) => {
res.header(“Access-Control-Allow-Origin”, “http://localhost:3000”);
res.header(
“Access-Control-Allow-Headers”,
“Origin, X-Requested-With, Content-Type, Accept, Authorization”
);
res.header(“Access-Control-Allow-Credentials”, true);
if (req.method === “OPTIONS”) {
res.header(
“Access-Control-Allow-Headers”,
“Origin, X-Requested-With, Content-Type, Accept, Authorization”
);
res.header(“Access-Control-Allow-Methods”, “GET, POST, PUT, DELETE, PATCH”);
return res.status(200).json({});
}
next();
});

Error=>
Access to XMLHttpRequest at ‘https://qa-chatbackend.onrender.com/signup’ from origin has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

but not get this error when run in local

Hi there,

This is likely an application-level issue, so we are limited in our ability to assist you here.

That said, on an initial look, you may need to adjust your Access-Control-Allow-Origin, as as the host will not be localhost in a hosted environment.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.