Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
fix: use callback function for cors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwigoric committed Nov 14, 2023
1 parent 716519b commit ca41cbd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ const app = express()

// Configure CORS
const whitelist = []
if (!process.env.FRONTEND_URL) console.warn('FRONTEND_URLS not set, allowing all origins')
if (!process.env.FRONTEND_URLS) console.warn('FRONTEND_URLS not set, allowing all origins')
else whitelist.push(...process.env.FRONTEND_URL.split(','))
app.use(
cors({
origin: (origin) => whitelist.length === 0 || whitelist.includes(origin),
origin: (origin, callback) => {
whitelist.length === 0 || whitelist.includes(origin)
? callback(null, true)
: callback(new Error('Not allowed by CORS'))
},
optionsSuccessStatus: 200
})
)
Expand Down

0 comments on commit ca41cbd

Please sign in to comment.