I am using tyk cloud. I have uploaded my swagger documentation for the API to the catalog.
In swagger file, I have set the url of my API. When I view the documentation in portal, and click the Try it out button, it tries to call http://[Organization].cloud.tyk.io/Api instead of the url I set inside swagger file.
Is it possible to override this behavior, and make it use the url in swagger file?
This feature has now been pushed to live. You should see the host + basepath override the URLs (both will be required to properly work) - you may need to refresh your browser too.
If your underlying target API already handles CORS, then all you will need to change is under “Advanced Settings” select “Options Pass through”, but do not enable CORS.
If you’re underlying target API does not handle CORS, then you can enable CORS in the gateway and add the relevant headers / allowed hosts in the settings screen.
See my post above. If your APi handles CORS, then you need to put al the settings into your service and just allow options pass through (do not enable anything)
If you are not handling CORS upstream, then you can put the required settings into Tyk:
Enable CORS
Set allowed hosts to *
Set Allowed methods to GET, PUT, POST, DELETE
Deselect Options passthrough
This will cause Tyk gateway to start blocking requests and handling CORS, be warned, if the upstream API also injects CORS headers, then you will get more errors becuase of the duplicate response headers.
I followed your instructions above. I have removed everything related to CORS from my local API. I have enabled CORS and added allowed domains = * and Allowed methods = GET in tyk cloud.
Unfortunately, it is still not working.
I have also checked on my side i.e. Firewall, web server and nothing has reached my endpoint. It seems that the request is not going out from the portal site.
Please find attached the request and response details from Chrome upon clicking on the “Try it out” button.
I’ve looked into your account, and think I know what is wrong:
Your APIs are configured with very specific listen paths that are case sensitive, e.g. /eventsrealtime/ in Tyk Cloud, which means your managed URLS would be:
Or, if you have the NGinX settings enabled to handle URL rewrites in your hybrid agent (I wouldn’t tackle this yet), then: http://your.custom.hybrid.domain/eventsrealtime
Now your swagger definitions are pointing directly at your API on your custom domain, under paths such as /EventsFullNoGeo/, which I think is a real endpoint name: If I visit this URL directly (as specified by your Swagger), I get a Windows server response that is not being in any way protected by Tyk, but I still get a 403 status code because the response is not allowed (probably because it’s not actually a public endpoint).
Your API Definitions all have *.local targets, so the only way to reach them is with a hybrid agent, assuming you have hybrid running, then you should be able to target this API via:
This means that CORS is the least of your problems, since your routing is totally off at the moment. and those requests from the swagger interface will never work since the 403 response that the CORS pre-flight is complaining about is coming from IIS, and not Tyk (we do not run Windows servers), and since Tyk isn’t managing that request, it can’t inject the required CORS headers to allow the pre-flight to pass.
I hope that helps a bit, I think the overall routing configuration is the problem here, I’d suggest:
Remove the Authentication from Tyk for now (for teting), less things to go wrong like wrong keys
Ensure you have Hybrid running (see our quickstart for Hybrid, it shows you how to handle a demo request)
Once you have requests working with postman or Curl, then come back here and we’ll talk about setting up the built-in NginX host to allow for friendly URLs
I have managed to make it work from documentation page following your instructions.
However, I still have one issue. There is a specific path in the api that accepts a custom header named “open511-version”. When I call this path from documentation page and pass a value for this header, I get the CORS error. If I don’t pass value for this header, it works correctly.
I have added this header to Allowed Headers in tyk api config. Unfortunately, it is still not working.