Enhance CORS configuration for browser compatibility #183
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.
Summary
Fixes CORS preflight failures that can occur when browsers send requests with custom headers or non-standard content types. This ensures Fluree Server works correctly with modern web applications making cross-origin requests.
Problem
The current CORS implementation uses
:anyfor allowed headers, which:When a browser sends a request with custom headers (like
Fluree-Identity) or non-simple content types (likeapplication/sparql-query), it first sends a preflight OPTIONS request. If the server doesn't respond correctly, the browser blocks the actual request entirely - the server never even sees it.Changes
1. Centralized Header Management
standard-request-headersconstant for common HTTP headersfluree-request-header-keysnow serves as single source of truthfluree-response-header-keysfor headers browsers can read2. Enhanced CORS Middleware
:anywith explicit header list from constantsAccess-Control-Expose-Headersso browsers can read Fluree response headersAccess-Control-Max-Age(24 hours) to cache preflight responses and reduce network overhead3. OPTIONS Route Handlers
Added explicit OPTIONS handlers returning 204 status to all endpoints:
/fluree/create,/drop,/transact,/update,/insert,/upsert/fluree/query,/history,/subscribe/fluree/remote/*endpoints4. Documentation
corsOriginsto README Configuration OptionsTesting
handler_cors_test.cljto verify header constants and middleware compositionSecurity Considerations
["https://app.example.com"])Backward Compatibility
✅ Fully backward compatible:
corsOriginsconfig continues to work