Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger-ui change URL #887

Closed
czchen opened this issue Feb 25, 2019 · 9 comments
Closed

swagger-ui change URL #887

czchen opened this issue Feb 25, 2019 · 9 comments
Labels

Comments

@czchen
Copy link

czchen commented Feb 25, 2019

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

@dtkav
Copy link
Collaborator

dtkav commented Feb 26, 2019

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.

@czchen
Copy link
Author

czchen commented Feb 26, 2019

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

@dtkav
Copy link
Collaborator

dtkav commented Feb 26, 2019 via email

@czchen
Copy link
Author

czchen commented Feb 27, 2019

flask

@dtkav
Copy link
Collaborator

dtkav commented Mar 2, 2019

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.

@dtkav dtkav added the bug label Mar 2, 2019
@czchen
Copy link
Author

czchen commented Mar 2, 2019

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.%       

@dtkav
Copy link
Collaborator

dtkav commented Mar 7, 2019

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>
<h1>Redirecting...</h1>
* 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.
✔ ~ > 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>
<h1>Redirecting...</h1>
* Closing connection 0

@dtkav dtkav added question and removed bug labels Mar 7, 2019
@dtkav
Copy link
Collaborator

dtkav commented Mar 7, 2019

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.

@maurommx
Copy link

image
url navigator other "server" -> "url", I need update swagger.json > server > url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants