CORS issue when working with express and react

I have deployed this express rest API using netlify
When ever I try to make a GET or PULL request using either postman or react or even simply curl, it returns this error:
Access to XMLHttpRequest at '' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

This is my netlify.toml file in the root of the server directory:

for = “/"
Access-Control-Allow-Origin = "

and this is my server.js in functionsconst express = require(“express”);
const serverless = require(“serverless-http”);
const cors = require(“cors”);
const mongoose = require(“mongoose”);

const app = express();
const router = express.Router();

const dbUrl =
“db url is here”;

const corsOptions = {
origin: ‘http://localhost:5173’,
credentials: false,
optionSuccessStatus: 200


const userRouter = require(“…/routes/users”);
const messageRouter = require(“…/routes/messages”);

router.use(“/users”, userRouter);
router.use(“/messages”, messageRouter);

router.get(“/”, (req, res) => {
res.send(“You got to the root. Yay!”);
// Define your routes
app.use(“/.netlify/functions/server”, router);

module.exports.handler = serverless(app);

I can get the pages from the browser but not programmatically. BTW this is how I am getting and posting onto the server (using axios)

It all works fine when I was running it on localhost but now it just doesnt’ work.

Thank you very much. I relized that i had allowed requests only from my 5173 localhost and wasn’t allowing any requests from the netlify app at all. Added that to the list so it works now. Thank you for your help!

Glad you found your solution! thanks for writing back in and sharing this with the community.