fix: add CORS headers to streaming chat response

Merged
SW
10mo ago
+7-2

Summary

  • Add CORS headers to createUIMessageStreamResponse call in handleChatStream.ts so streaming responses include proper CORS headers
  • Add x-api-key to Access-Control-Allow-Headers in getCorsHeaders.ts since the /api/chat endpoint requires API key authentication
  • Update handleChatStream.test.ts to expect CORS headers in the streaming response

Problem

Cross-origin requests to /api/chat from client interfaces (e.g., http://localhost:3000 to https://test-recoup-api.vercel.app/api/chat) were being blocked with:

Access to fetch at 'https://test-recoup-api.vercel.app/api/chat' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

The OPTIONS handler and error responses already included CORS headers, but the successful streaming response did not.

Test plan

  • Verify /api/chat requests from cross-origin clients no longer fail with CORS errors
  • Verify streaming responses include Access-Control-Allow-Origin: * header
  • Verify x-api-key header is allowed in preflight requests

šŸ¤– Generated with Claude Code