CORS error with Express

Hello, when i try to register on my app on localhost (front + back) it works, but when i try to register with the back being host by Fly.io, i have this error that shows up :

Acess to fetch at 'https://<my fly url>.fly.dev/register' from origin 'http://localhost:19006' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

to deal with CORS, i use this code :

const cors = require('cors');


const app = express();
const frontUrl = process.env.FRONT_URL || "http://localhost:19006";

app.use("/", cors({ origin: frontUrl }));
const port = 8080;

but it doesn’t want to work :smiling_face_with_tear:
i also have this on my fly console when i press register :

[GIN] 2023/07/07 - 12:00:44 | 404 | 820ns | 92.188.66.18 | OPTIONS /register

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