I have tried allowing CORS for months, and it just doesn't work, here's my server.js file (main file):
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const http = require('http');
const app = express();
const server = http.createServer(app);
const PORT = Number(process.env.PORT) || 3000;
const allowedOrigins = [
'https://dashboard.zsulesportes.com',
'http://localhost:3000'
];
app.use(cors({
origin: '*'
}));
app.use(express.json());
// app.use(helmet());
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
res.setHeader('Content-Type', 'application/json; charset=utf-8');
next();
});
This is what I have defined before my routes.