0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 14:12:40 +00:00

add heroku apps to cors

This commit is contained in:
Víctor Losada Hernández
2024-12-09 18:59:48 +01:00
parent 4eb8abf1e7
commit 81f56ec91d

View File

@@ -59,18 +59,20 @@ import cors from 'cors';
// CORS Configuration
const corsOptions = {
origin: (origin, callback) => {
const allowedOrigins = [
'https://homebrewery.naturalcrit.com',
'http://localhost:8000',
'http://localhost:8010',
'https://naturalcrit.com'
]; //allow natcrit local and live to call
if (!origin || allowedOrigins.includes(origin)) {
'https://homebrewery.naturalcrit.com',
'http://localhost:8000',
'http://localhost:8010',
'https://naturalcrit.com'
];
const herokuRegex = /^https:\/\/.*\.herokuapp\.com$/; // Matches any Heroku app
if (!origin || allowedOrigins.includes(origin) || herokuRegex.test(origin)) {
callback(null, true);
} else {
console.log(origin, 'not allowed');
console.log(origin, 'not allowed');
callback(new Error('Not allowed by CORS, if you think this is an error, please contact us'));
}
},
@@ -78,6 +80,7 @@ const corsOptions = {
credentials: true,
};
app.use(cors(corsOptions));
//Account Middleware