cancel
Showing results for 
Search instead for 
Did you mean: 

Change domain for 'try it out' feature

SOLVED
Occasional Contributor

Change domain for 'try it out' feature

Hi,

So currently I'm using the standalone version of swaggerUIBundle:

window.onload = function () {
   // Begin Swagger UI call region
   const ui = SwaggerUIBundle({})
}

 On the front-end. When I enter the "try it out" feature and press the execute button; the request URL and the cURL string are both using the same domain which my page is on. My API sits on another domain however and so the response returns a page not found (as you would expect). Is there a config setting allowing me to serve my APIs from another domain?

 

Thanks

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: Change domain for 'try it out' feature

You need to enable CORS on your API server, localhost:8007. The way you do this depends on the server and framework used, check out https://enable-cors.org/server.html

 

Alternatively, hosting Swagger UI on the same server:port as the API server will avoid CORS altogether.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

6 REPLIES 6
Moderator

Re: Change domain for 'try it out' feature

You need to specify the target server in your API definition, for example:

 

openapi: 3.0.0
servers:
  - url: 'https://example.com/api'

 

or

 

swagger: '2.0'

host: example.com
basePath: /api
schemes:
  - https

 

 


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Occasional Contributor

Re: Change domain for 'try it out' feature

hi,

Thanks for that. Using your first option - the URLs are now pointing at my API on the correct domain. I still have an issue where the server fails to load the response:-

 

Screenshot 2020-12-01 at 13.23.24.png 

 

I've checked the above in my local browser and the payload returns successfully.

 

Thanks

 

 

Moderator

Re: Change domain for 'try it out' feature

What's the error message in the Console tab of the browser developer tools?


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Occasional Contributor

Re: Change domain for 'try it out' feature

Ah, yes - It's a CORS issue:-

Screenshot 2020-12-01 at 13.35.38.png

 

How do we get over this hurdle? Am I able to configure Docker to get around this?

 

Thanks for all your help and a great piece of software.

Moderator

Re: Change domain for 'try it out' feature

You need to enable CORS on your API server, localhost:8007. The way you do this depends on the server and framework used, check out https://enable-cors.org/server.html

 

Alternatively, hosting Swagger UI on the same server:port as the API server will avoid CORS altogether.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

Occasional Contributor

Re: Change domain for 'try it out' feature

Thanks Helen

New Here?
Join us and watch the welcome video:
Announcements