Add comprehensive CORS support with Cross-Origin-Resource-Policy for all API endpoints #98
+168
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The API was not properly handling CORS (Cross-Origin Resource Sharing) requests across all endpoints, preventing web applications from making cross-origin requests. While a global CORS configuration existed in
config/initializers/cors.rb, it wasn't being applied correctly to endpoints that usesend_data()to return binary content, and the Cross-Origin-Resource-Policy header was missing.Root Cause
The issue occurred because:
send_data()to return binary contentSolution
This PR adds comprehensive CORS handling for all API endpoints with minimal changes:
Global CORS Support
ApplicationControllerviabefore_actionto ensure all endpoints support CORS when anOriginheader is presentcross-originfor all responses to allow cross-origin resource accessEndpoint-Specific Changes
Cross-Origin-Resource-Policy: cross-originTesting
Example Usage
After this change, web applications can make cross-origin requests to any API endpoint:
Backward Compatibility
These changes are fully backward compatible - existing functionality is preserved while adding comprehensive CORS support for all cross-origin requests.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.