CORS Configuration
Configure CORS (Cross-Origin Resource Sharing) in moclojer for local development, testing, and cross-domain API access with proper headers.
Configure CORS headers in moclojer for cross-origin requests.
π― Enable CORS
Environment Variable
MOCLOJER_ENABLE_CORS=true moclojer --config mocks.ymlManual Headers
- endpoint:
method: OPTIONS
path: /api/users
response:
status: 204
headers:
Access-Control-Allow-Origin: "*"
Access-Control-Allow-Methods: "GET, POST, PUT, DELETE, OPTIONS"
Access-Control-Allow-Headers: "Content-Type, Authorization"
Access-Control-Max-Age: "86400"
body: ""
- endpoint:
method: GET
path: /api/users
response:
status: 200
headers:
Access-Control-Allow-Origin: "*"
Content-Type: application/json
body: >
{"users": []}π Specific Origins
β
Best Practices
Development:
Use
Access-Control-Allow-Origin: "*"
Production:
Specify exact origins
Avoid wildcards
Use credentials carefully
π See Also
Last updated
Was this helpful?