fix: remove explicit OPTIONS handler causing path-to-regexp error

This commit is contained in:
soufiane 2025-12-07 17:42:12 +01:00
parent 1f2ecd0f09
commit cc1997b099

View File

@ -20,32 +20,6 @@ import contactRoutes from "./src/routes/contact.routes.js";
const app = express(); const app = express();
// Handler explicite pour les requêtes preflight OPTIONS
app.options('*', (req, res) => {
const allowedOrigins = [
"http://localhost:3000",
"http://localhost:3001",
"http://localhost:3002",
"http://localhost:3003",
"http://localhost:3004",
"http://localhost:3005",
"https://dsp5-archi-o24a-15m-g3.fr",
"https://dev.dsp5-archi-o24a-15m-g3.fr",
"https://preprod.dsp5-archi-o24a-15m-g3.fr"
];
const origin = req.headers.origin;
if (!origin || allowedOrigins.includes(origin)) {
res.header('Access-Control-Allow-Origin', origin || '*');
} else {
res.header('Access-Control-Allow-Origin', origin); // Autorise tout en dev
}
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Max-Age', '86400');
res.sendStatus(204);
});
// CORS doit être configuré AVANT helmet // CORS doit être configuré AVANT helmet
app.use( app.use(
cors({ cors({