Skip to content

Commit 6e6471c

Browse files
Fix CORS preflight and allow Codesignal preview origins
1 parent c329b02 commit 6e6471c

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/main.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,16 @@ async function bootstrap() {
1313
const app = await NestFactory.create<NestExpressApplication>(AppModule);
1414
app.enableCors({
1515
origin: (origin, callback) => {
16-
// Allow same-origin requests (like curl or health checks where no origin header is present)
17-
if (!origin) {
18-
return callback(null, true);
19-
}
20-
21-
// Explicitly allow localhost:3000 for local dev
22-
if (origin === 'http://localhost:3000') {
23-
return callback(null, true);
24-
}
25-
26-
// Allow any Codesignal preview subdomain
16+
if (!origin) return callback(null, true);
17+
if (origin === 'http://localhost:3000') return callback(null, true);
2718
if (/^https:\/\/[a-z0-9-]+\.preview\.codesignal\.dev$/.test(origin)) {
2819
return callback(null, true);
2920
}
30-
31-
// Otherwise block
3221
return callback(new Error(`CORS blocked for origin: ${origin}`), false);
3322
},
3423
credentials: true,
24+
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
25+
allowedHeaders: ['Content-Type', 'Authorization'],
3526
});
3627

3728
app.useGlobalPipes(

0 commit comments

Comments
 (0)