refactor(cors): simplify origin validation logic in index.ts
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:
2025-12-18 13:54:41 +01:00
parent c9d067b1e3
commit c289541cd5

View File

@ -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,