flask-restplus
flask-restplus copied to clipboard
Use relative swagger.json URL for SwaggerUI
I run my flask-restplus app in the default werkzeug HTTP webserver behind a reverse HTTPS proxy. The absolute URL of the swagger.json is problematic for the SwaggerUI AJAX call in this scenario. All of the other resources in the HTML use relative URLs anyways.
Why is that ? Can you precise your initial issue ? Have you set SERVER_URL in your configuration and added ProxyFix ? I'm using this setup in production and it's working very well. See http://flask.pocoo.org/docs/0.10/deploying/wsgi-standalone/#deploying-proxy-setups (this Flask related, not specific to flask-restplus)
I'm not sure that using the path is compatible with subdomain blueprints.
The issue is the conflict with http and https in the full URL. flask-restplus generates the URL with http:// but my reverse proxy load balancer only accepts https://, so the swagger.json will never load via AJAX call. I do not have ProxyFix. I do not have control over the headers that can be set by the load balancer.
I'm not sure what you mean by subdomain blueprints, but isn't the hostname of swagger.json and the SwaggerUI elements always the same? Alternatively, we could have the URL with the hostname but without the scheme (i.e. "//server.com/swagger.json") and it will load properly. Why should flask-restplus should care what the hostname is?
No, you can have different URL for documentation and API so absolute URL is necessary. Blueprint can be registered with an url prefix and/or a given subdomain (see #103).
Your reverse proxy (NGinx or HAProxy or whatever) send an X-Forwarded-Proto
header which is standard which and handled by ProxyFix (it's not a new dependency but a Werkzeug middleware, see the previous link).
This is how Flask is meant to run (and which is explain in the link).
See also #54 because someone already asked for this.
Just so you know, I have the same setup in production (a frontal load balancer performing the SSL offload itself and talking with my app in HTTP) and it's been working fine with ProxyFix for almost 2 years.
Ah OK. Would dropping the scheme be a compromise? Its generally a best practice in web sites to not require http/https scheme in AJAX URLs in HTML, so that it picks up the parent page's scheme.
@noirbizarre could we get an nginx and other sample configuration files uploaded with the examples as this is a common scenario.
Hi @noirbizarre how can i change the swagger.json url. since i don't want to serve swagger.json on hostname/swagger.json. Instead i want to host it at different url such as hostname/_svc/api/swagger.json
Can it be merged? I am having issue running Flask on HTTPS.
Exact same problem here, this is a huge blocker for me because HTTPS won't work at all behind my reverse proxy