mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-19 14:12:40 +00:00
add heroku apps to cors
This commit is contained in:
@@ -59,15 +59,17 @@ 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');
|
||||||
@@ -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