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) => {
|
origin: (origin, cb) => {
|
||||||
// Allow requests with no origin (like mobile apps or curl)
|
// Allow requests with no origin (like mobile apps or curl)
|
||||||
if (!origin) {
|
if (!origin) {
|
||||||
cb(null, true);
|
return cb(null, true);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if origin is in allowed list
|
// Check if origin is in allowed list
|
||||||
if (allowedOrigins.some(allowed => origin === allowed || origin.endsWith(allowed))) {
|
const isAllowed = allowedOrigins.includes(origin);
|
||||||
cb(null, true);
|
|
||||||
|
if (isAllowed) {
|
||||||
|
return cb(null, true);
|
||||||
} else {
|
} else {
|
||||||
cb(new Error('Not allowed by CORS'), false);
|
return cb(null, false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
credentials: true,
|
credentials: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user