Connexion: swagger-ui change URL

Created on 25 Feb 2019  Â·  8Comments  Â·  Source: zalando/connexion

Description

We put our connexion application in k8s. But when we access swagger-ui via https://example.com/v0/ui, it is redirected to http://127.0.0.1:5000/v0/ui so we cannot use swagger UI. All other URLs in example.com are not redirected, so we think the problem is in swagger-ui.

Expected behaviour

When access https://example.com/v0/ui, we shall be about to access swagger-ui

Actual behaviour

When access https://example.com/v0/ui, we are redirected to http://127.0.0.1:5000/v0/ui.

Steps to reproduce

Additional info:

Output of the commands:

  • python --version

$ python --version
Python 3.7.2+

  • pip show connexion | grep "^Version\:"

$ pip show connexion | grep "^Version\:"
Version: 2.2.0

question

Most helpful comment

hey @czchen,

Can you please provide the servers block of your specification? Also, are you explicitly setting base_path?

This may be caused by a trailing-slash redirect. Can you try https://example.com/v0/ui/ (with trailing slash) and let me know if you are still having the issue?

I think the issue may also fixed by #823 - the goal of that diff is to fix connexion behavior when behind a reverse-proxy.

All 8 comments

hey @czchen,

Can you please provide the servers block of your specification? Also, are you explicitly setting base_path?

This may be caused by a trailing-slash redirect. Can you try https://example.com/v0/ui/ (with trailing slash) and let me know if you are still having the issue?

I think the issue may also fixed by #823 - the goal of that diff is to fix connexion behavior when behind a reverse-proxy.

  • The servers block is:
servers:
  - url: /v0

ok, thanks for the info.
Are you using aiohttp or flask?

On Wed, Feb 27, 2019, 1:58 AM ChangZhuo Chen (陳昌倬) notifications@github.com
wrote:

>

  • The servers block is:

servers:

  • url: /v0

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/zalando/connexion/issues/887#issuecomment-467470319,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAlPScaHxA6Pndz__Fl2gtXQYfrTcxlAks5vRUt4gaJpZM4bPWRO
.

flask

My guess is that strict_slashes in werkzeug is causing a redirect, but it's redirecting to your local IP, not the host you are exposing the site on.

Can you include the output of a verbose curl request?
Your original post states that the redirect is from:

https://example.com/v0/ui, we are redirected to http://127.0.0.1:5000/v0/ui.

But I would expect the redirected url to include the trailing slash like so:

https://example.com/v0/ui redirected to http://127.0.0.1:5000/v0/ui/

Also if you have time, can you try out #823 and see if that fixes your issue?
I've been trying to get that merged for a while to fix this type of problem.

The following is output of `curl --verbose http://exampke.com/v0/ui.

ps. We change our auth sidecar from keycloak-gatekeeper to nginx, the redirect URL is also changed.

< HTTP/1.1 301 MOVED PERMANENTLY                   
< Content-Type: text/html; charset=utf-8                      
< Date: Sat, 02 Mar 2019 03:17:04 GMT            
< Location: http://example.com:8080/v0/ui/ 
< Server: nginx/1.13.12                          
< Content-Length: 263                            
< Connection: keep-alive                         
<                                                
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>                    
<h1>Redirecting...</h1>                          
* Connection #0 to host example.com left intact
<p>You should be redirected automatically to target URL: <a href="http://localhost:5000/v0/ui/">http://localhost:5000/v0/ui/</a>.  If not click the link.%       

ps. We change our auth sidecar from keycloak-gatekeeper to nginx, the redirect URL is also changed.
Do you have any output to show this behavior?

I think this may be related to your nginx configuration.

I wasn't able to reproduce your issue.
Here's what I did:

cd /tmp/
git  clone https://github.com/zalando/connexion.git
cd connexion/
touch Pipfile
pipenv install -e .[swagger-ui]
pipenv shell
cd examples/openapi3/helloworld/
python hello.py

After this I tried to access the ui without the trailing slash, and the redirect looks correct to me:

✔ ~ > curl -vv localhost:9090/v1.0/ui

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9090 (#0)
> GET /v1.0/ui HTTP/1.1
> Host: localhost:9090
> User-Agent: curl/7.58.0
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 301 MOVED PERMANENTLY
< Content-Type: text/html; charset=utf-8
< Content-Length: 267
< Location: http://localhost:9090/v1.0/ui/
< Server: Werkzeug/0.14.1 Python/3.6.7
< Date: Thu, 07 Mar 2019 01:10:14 GMT
< 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
* Closing connection 0
<p>You should be redirected automatically to target URL: <a href="http://localhost:9090/v1.0/ui/">http://localhost:9090/v1.0/ui/</a>.  If not click the link.
✔ ~ >curl -vv localtest.me:9090/v1.0/ui

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localtest.me (127.0.0.1) port 9090 (#0)
> GET /v1.0/ui HTTP/1.1
> Host: localtest.me:9090
> User-Agent: curl/7.58.0
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 301 MOVED PERMANENTLY
< Content-Type: text/html; charset=utf-8
< Content-Length: 273
< Location: http://localtest.me:9090/v1.0/ui/
< Server: Werkzeug/0.14.1 Python/3.6.7
< Date: Thu, 07 Mar 2019 01:10:35 GMT
< 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>


md5-79aefe177c1f51034bfddaa639123ee9


* Closing connection 0
<p>You should be redirected automatically to target URL: <a href="http://localtest.me:9090/v1.0/ui/">http://localtest.me:9090/v1.0/ui/</a>.  If not click the link.



md5-b970d9b2b7b9c7575bc0d5f111f80e8f



✔ ~ > curl -vv connexion.localtest.me:9090/v1.0/ui

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to connexion.localtest.me (127.0.0.1) port 9090 (#0)
> GET /v1.0/ui HTTP/1.1
> Host: connexion.localtest.me:9090
> User-Agent: curl/7.58.0
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 301 MOVED PERMANENTLY
< Content-Type: text/html; charset=utf-8
< Content-Length: 293
< Location: http://connexion.localtest.me:9090/v1.0/ui/
< Server: Werkzeug/0.14.1 Python/3.6.7
< Date: Thu, 07 Mar 2019 01:10:45 GMT
< 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>


md5-79aefe177c1f51034bfddaa639123ee9


* Closing connection 0

I've changed the ticket type to question.
Feel free to close the ticket. Otherwise, if you post your configuration I can try to help you debug it.

Was this page helpful?
0 / 5 - 0 ratings