File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,25 @@ import { LogsService } from './common/logging/logs.service';
1212async function bootstrap ( ) {
1313 const app = await NestFactory . create < NestExpressApplication > ( AppModule ) ;
1414 app . enableCors ( {
15- origin : [
16- 'http://localhost:3000' ,
17- / \. p r e v i e w \. c o d e s i g n a l \. d e v $ / , // allow any Codesignal preview frontend
18- ] ,
15+ 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
27+ if ( / ^ h t t p s : \/ \/ [ a - z 0 - 9 - ] + \. p r e v i e w \. c o d e s i g n a l \. d e v $ / . test ( origin ) ) {
28+ return callback ( null , true ) ;
29+ }
30+
31+ // Otherwise block
32+ return callback ( new Error ( `CORS blocked for origin: ${ origin } ` ) , false ) ;
33+ } ,
1934 credentials : true ,
2035 } ) ;
2136
@@ -43,7 +58,6 @@ async function bootstrap() {
4358 ) ;
4459
4560 const port = Number ( process . env . PORT ) || 3001 ;
46-
4761 await app . listen ( port ) ;
4862 console . log ( `Application is running on: http://localhost:${ port } ` ) ;
4963}
You can’t perform that action at this time.
0 commit comments