mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-27 17:38:51 +05:00
new fix CORS
This commit is contained in:
21
src/index.js
21
src/index.js
@@ -104,13 +104,24 @@ const swaggerOptions = {
|
||||
const swaggerDocs = swaggerJsdoc(swaggerOptions);
|
||||
|
||||
// CORS configuration
|
||||
const corsOptions = {
|
||||
origin: [
|
||||
const allowedOrigins = [
|
||||
'http://localhost:3000',
|
||||
'https://neo-movies.vercel.app',
|
||||
'https://neomovies.sofron.ru',
|
||||
/\.vercel\.app$/
|
||||
],
|
||||
'https://neomovies.sofron.ru'
|
||||
];
|
||||
|
||||
const corsOptions = {
|
||||
origin: function (origin, callback) {
|
||||
// Разрешаем запросы без origin (например, от мобильных приложений или curl)
|
||||
if (!origin) return callback(null, true);
|
||||
|
||||
// Разрешаем, если домен есть в списке или это превью-сборка Vercel
|
||||
if (allowedOrigins.indexOf(origin) !== -1 || /\.vercel\.app$/.test(origin)) {
|
||||
callback(null, true);
|
||||
} else {
|
||||
callback(new Error('Not allowed by CORS'));
|
||||
}
|
||||
},
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
allowedHeaders: ['Content-Type', 'Authorization'],
|
||||
credentials: true,
|
||||
|
||||
Reference in New Issue
Block a user