@@ -39,7 +39,7 @@ public async Task InvokeAsync(HttpContext context)
3939 } ) ;
4040
4141 // Log incoming request with structured data
42- _logger . LogInformation ( "Processing {Method} {Path} from {RemoteIP} with correlation ID {CorrelationId}" ,
42+ _logger . LogDebug ( "Processing {Method} {Path} from {RemoteIP} with correlation ID {CorrelationId}" ,
4343 context . Request . Method , context . Request . Path ,
4444 context . Connection . RemoteIpAddress ? . ToString ( ) ?? "unknown" , correlationId ) ;
4545
@@ -70,7 +70,17 @@ public async Task InvokeAsync(HttpContext context)
7070
7171 private static void AddCorsHeaders ( HttpContext context )
7272 {
73- context . Response . Headers . Append ( "Access-Control-Allow-Origin" , "*" ) ;
73+ var allowedOrigins = Environment . GetEnvironmentVariable ( "ALLOWED_ORIGINS" ) ? . Split ( ',' ) ?? new [ ] { "*" } ;
74+ var origin = context . Request . Headers [ "Origin" ] . FirstOrDefault ( ) ;
75+
76+ if ( origin != null && allowedOrigins . Contains ( origin , StringComparer . OrdinalIgnoreCase ) )
77+ {
78+ context . Response . Headers . Append ( "Access-Control-Allow-Origin" , origin ) ;
79+ }
80+ else if ( allowedOrigins . Contains ( "*" ) )
81+ {
82+ context . Response . Headers . Append ( "Access-Control-Allow-Origin" , "*" ) ;
83+ }
7484 context . Response . Headers . Append ( "Access-Control-Allow-Methods" , "GET, POST, OPTIONS" ) ;
7585 context . Response . Headers . Append ( "Access-Control-Allow-Headers" , "Content-Type, Authorization, X-Correlation-ID, X-Client-Id" ) ;
7686 context . Response . Headers . Append ( "Access-Control-Expose-Headers" , "X-Correlation-ID, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset" ) ;
0 commit comments