refactor(cors): simplify origin validation logic in index.ts
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Streamlined CORS logic by consolidating `allowedOrigins` checks and improving readability. - Updated callback invocations for consistency and clarity.
This commit is contained in:
@ -46,15 +46,16 @@ fastify.register(cors, {
|
||||
origin: (origin, cb) => {
|
||||
// Allow requests with no origin (like mobile apps or curl)
|
||||
if (!origin) {
|
||||
cb(null, true);
|
||||
return;
|
||||
return cb(null, true);
|
||||
}
|
||||
|
||||
// Check if origin is in allowed list
|
||||
if (allowedOrigins.some(allowed => origin === allowed || origin.endsWith(allowed))) {
|
||||
cb(null, true);
|
||||
const isAllowed = allowedOrigins.includes(origin);
|
||||
|
||||
if (isAllowed) {
|
||||
return cb(null, true);
|
||||
} else {
|
||||
cb(new Error('Not allowed by CORS'), false);
|
||||
return cb(null, false);
|
||||
}
|
||||
},
|
||||
credentials: true,
|
||||
|
||||
Reference in New Issue
Block a user