Prerequisites
- Developer Portal is deployed and accessible
- Tyk Gateway and Dashboard are running
- At least one API product is configured and published in the Portal
- You know the public URL of your Live Portal (for example,
https://portal.example.com) - You know the public URL of your Tyk Gateway (for example,
https://api.example.com)
Configure Portal Application CORS
Portal application CORS controls which external origins may call the Portal’s own Admin API and Live Portal routes. It is configured via environment variables on the Portal process.-
Enable CORS
Set PORTAL_CORS_ENABLE to
trueon the Portal process.- Environment variable
- Config file
-
Set allowed origins
Set PORTAL_CORS_ALLOWED_ORIGINS to the origins permitted to make cross-origin requests to the Portal. Use the exact scheme and host of each origin, separated by commas. Wildcards are supported.
When unset, the Portal responds with
Access-Control-Allow-Origin: *. Because Portal uses cookie-based sessions, browsers block credentialed requests to a wildcard origin. Specify individual origins to restrict access, or set tohttp://*,https://*to allow all origins.- Environment variable
- Config file
-
Set allowed headers and methods
Set the HTTP headers and methods that cross-origin requests to the Portal may use. No headers are allowed by default. The default allowed methods are
GETandPOST.- Environment variable
- Config file
-
(Optional) Configure additional CORS settings
Config key Default Description CORS.MaxAge 0How long, in seconds, browsers may cache the preflight response. A positive value reduces preflight round trips. CORS.AllowCredentials falseWhether the Portal includes credentials (cookies, HTTP authentication) in CORS responses. - Restart the Portal Restart the Portal process or pod for the environment variable changes to take effect.
-
Verify
Open your browser developer tools and make a cross-origin request to the Portal from an allowed origin. The response headers should include
Access-Control-Allow-Originand the request should succeed.
Configure Gateway CORS for APIs
When a consumer tests an API using the API Playground on the Live Portal, the browser makes requests directly to the Tyk Gateway. The Portal does not proxy these requests and does not inject CORS headers. You must configure CORS on the API definition for each API exposed through the Portal.-
Locate the CORS block
In a Tyk OAS API definition, CORS configuration sits under
x-tyk-api-gateway.middleware.global.cors. -
Add the CORS configuration
Set
optionsPassthroughtofalse(the default). Whenfalse, the Gateway intercepts OPTIONS preflight requests, responds with CORS headers, and does not forward the request to the upstream. - Update the API Update the API definition in Tyk Dashboard.
- Verify Open the API Playground on your Live Portal and send a test request. The request should complete without CORS errors in the browser console.
If you are using a Tyk Classic API definition, configure CORS in Tyk Dashboard under APIs > Advanced Options > CORS. See the Classic API CORS reference for details.
Related
- Troubleshoot CORS Issues — diagnose and fix common CORS errors in the Developer Portal and API Playground