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

Completely blank white swagger page, browser reports failure to retrieve files from nonsense URLs

Open LordZorgoth opened this issue 2 years ago • 2 comments

Flask is looking for Swagger files at nonsense locations, e.g. http://swagger-ui-standalone-preset.js/, and I get a blank white page upon loading my Swagger path. gunicorn and Python report no errors, and my API works fine apart from the Swagger page.

Firefox reports the following:

Failed to load resource: net::ERR_EMPTY_RESPONSE
swagger-ui-bundle.js/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE
swagger-ui.css/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE
index.css/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE
(index):22 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at (index):22:9
favicon-32x32.png/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE
favicon-16x16.png/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE

LordZorgoth avatar May 24 '22 23:05 LordZorgoth

Update: If I set the path to something other than '/', it works. However, it only works if I serve all of the Swagger files manually, which doesn't seem right.

LordZorgoth avatar May 25 '22 00:05 LordZorgoth

I have the same problem. Flask is running on subdomain and is configured via SCRIPT_NAME environment variable (https://dlukes.github.io/flask-wsgi-url-prefix.html). Flask_swagger_ui is configured with base_url set to /swagger-ui/ and so is running on /subdomain/swagger-ui/.

However, the page is blank with same errors as above because links to javascript, icons and css resources in the flask_swagger_ui template (index.template.html) are not respecting subdomain setting, only base_url. So Flask is looking for them at /swagger-ui/<resource> instead of /subdomain/swagger-ui/<resource>.

So I replaced all {{ base_url }} in flask_swagger_ui's template (index.template.html) to {{ url_for('.show') }} (to generate proper link to flask_swagger_ui blueprint endpoint show which is also in charge of serving all resources). Everything is working OK after that.

mprusak avatar Jun 09 '22 06:06 mprusak