mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-15 17:02:38 +00:00
add heroku apps to cors
This commit is contained in:
@@ -59,18 +59,20 @@ import cors from 'cors';
|
|||||||
|
|
||||||
// CORS Configuration
|
// CORS Configuration
|
||||||
const corsOptions = {
|
const corsOptions = {
|
||||||
|
|
||||||
origin: (origin, callback) => {
|
origin: (origin, callback) => {
|
||||||
const allowedOrigins = [
|
const allowedOrigins = [
|
||||||
'https://homebrewery.naturalcrit.com',
|
'https://homebrewery.naturalcrit.com',
|
||||||
'http://localhost:8000',
|
'http://localhost:8000',
|
||||||
'http://localhost:8010',
|
'http://localhost:8010',
|
||||||
'https://naturalcrit.com'
|
'https://naturalcrit.com'
|
||||||
]; //allow natcrit local and live to call
|
];
|
||||||
if (!origin || allowedOrigins.includes(origin)) {
|
|
||||||
|
const herokuRegex = /^https:\/\/.*\.herokuapp\.com$/; // Matches any Heroku app
|
||||||
|
|
||||||
|
if (!origin || allowedOrigins.includes(origin) || herokuRegex.test(origin)) {
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
} else {
|
} 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'));
|
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,
|
credentials: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
app.use(cors(corsOptions));
|
app.use(cors(corsOptions));
|
||||||
|
|
||||||
//Account Middleware
|
//Account Middleware
|
||||||
|
|||||||
Reference in New Issue
Block a user