CORS issue when frontend tries to send api request to backend

Netlify frontend URL: https://stayfit-client.netlify.app/
My Render backend URL: https://stayfit-backend-xv9v.onrender.com

It leads to a sign-in page. However, when I try to sign in, I get the following error -

My app.ts file -

import { Server } from "@overnightjs/core";
import { initDB } from "./models";
import { ApiController } from "./controllers/ApiController";
import * as bodyParser from "body-parser";
import session from "express-session";
import cookieParser  from "cookie-parser";
import * as http from 'http';
import cors from 'cors';

export class App extends Server {
	private close: http.Server;

	constructor() {
		super();
		// setting up session
		this.app.use(
			session({
				secret: "secret",
				resave: true,
				saveUninitialized: true,
				cookie: {maxAge: 60 * 1000 * 300},
				rolling: true // reset exipration date with every request
			})
		);
		this.applyMiddleWares();
		this.boostrap();
		this.setupControllers();
	}

	public start(): void {
		const port = 10000;

		this.app.use((req, res, next) => {
			res.header('Access-Control-Allow-Origin', '*');
			res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
			next();
		});

		// Enable CORS for all routes
		this.app.use(cors());

		// Use the cookie-parser middleware
		this.app.use(cookieParser());

		this.close = this.app.listen(port, () => {
            console.log('Server listening on port: ' + port);
        });

	}

	private applyMiddleWares() {
		this.app.use(bodyParser.json());
		this.app.use(bodyParser.urlencoded({ extended: false }));
	}

	private async boostrap() {
		// Connect to db
		await initDB();
	}

	private setupControllers() {
		super.addControllers(new ApiController());
	}
}

The issue is that the backend isn’t sending the appropriate headers in the preflight request. This is not an issue with the frontend on Netlify.

All of your CORS headers appear to be defined correctly within the start method, but I don’t see this being called anywhere. Maybe you intended to call this.start(); within the constructor?

I’ve added this.start(); in the constructor but now I get this error -

I’ve changed the port to 3001 and 4000 but I get the same error.

Are you trying to run this on render?

the backend is running on render…it is fully functional

As mentioned by @jasiqli, this is not a Netlify issue. You can always use Rewrites: Rewrites and proxies | Netlify Docs to make the browser believe these are same-origin requests.