I'm having a strange issue with express cors. My Cors config works fine on localhost but it isn't working on the production. I'm always getting this error.
Failed to load https://my-movie-db-backend-roberto.herokuapp.com/auth/login: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://my-movie-db-roberto.herokuapp.com' is therefore not allowed access. The response had HTTP status code 503. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
This is my cors configuration:
import * as cors from "cors";
const corsConfig: cors.CorsOptions = {
origin: ["https://my-movie-db-roberto.herokuapp.com", "http://localhost:3000"],
credentials: true,
methods: "GET,HEAD,OPTIONS,PUT,PATCH,POST,DELETE"
};
app.use(cors(corsConfig));
// add your routes
<MY-Routes>
// enabling pre-flight
app.options("*", cors(corsConfig));
I have been around this for some time now and I decide that it would be better ask for help, thanks ;-)