swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Accessing swagger ui endpoints behind a reverse proxy?

Open mautini opened this issue 3 years ago • 2 comments

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrome
  • Version: 99
  • Method of installation: flasgger
  • Swagger-UI version: ?
  • Swagger/OpenAPI version: Swagger 2.0

How can we help?

Let's assume I have a Flask app exposing an endpoint /login and I expose this app behind a reverse proxy (traefik) using the prefix my_app (the proxy has to strip the prefix, however when I use the "try it out" function in swagger ui, it send the request to /my_app/login and my app doesn't know this route).

With this configuration, I can't reach the Swagger UI: if I set url_prefix to my_app in Flask configuration, the documentation will be exposed on /my_app/apidocs but the proxy will strip the first part of the path. I can "cheat" by accessing /my_app/my_app/apidocs but the page doesn't load (css, js etc...) because it will call my_app/swagger-ui-bundle.js for example (and the my_app will be stripped by the proxy).

Is there any way to set the prefix only when accessing the ressources of the swagger ui?

To recap I would like to have the following endpoints exposed :

  • /login
  • /apidocs
  • /* (swagger resources)

but when I'm loading the ui, I would like to perform requests to /my_app/* (similarly to the try it out functionality where I can use basePath

Thanks

mautini avatar Mar 29 '22 17:03 mautini

Isn't there any progress since 2022?

kzlsahin avatar Nov 14 '24 10:11 kzlsahin

check this solution : https://github.com/apigee-127/swagger-tools/issues/342#issuecomment-906137693

erdemsarigh avatar Oct 30 '25 17:10 erdemsarigh