If I try to deliver the Swagger UI using Flask RestPlus over HTTPS, I see only the "No spec provided" error message at the root URL, and the full Swagger UI never loads. However, if I visit the API endpoints they return responses as expected.
Looking at the source HTML for the error page, I noticed that swagger.json
was being fetched from http://myhost/
rather than https://myhost/
I've discovered exactly the same issue on the restplus Github issues
I've fixed my issue temporarily with the monkey-patch mentioned on that page. The Swagger UI loads, and looking at the HTML source I see that swagger.json
is indeed fetched from https://myhost
.
Why is this happening, and how can I fix it without the monkey-patching?
HTTPS is courtesy of Cloudflare's "flexible" HTTPS service.
My app is behind Nginx which is configured thus, and hasn't been causing any issues as far as I'm aware:
...
http {
...
server {
location / {
charset UTF-8;
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
charset UTF-8;
proxy_intercept_errors on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:5000;
}
}
}
I have used below to get it worked. You can view the stable example in below link.
http://flask-restplus.readthedocs.io/en/stable/example.html
from werkzeug.contrib.fixers import ProxyFix
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With