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

webflux: contextPath not used while behind a load balancer/reverse proxy #1109

Closed
mxmrlt opened this issue Mar 16, 2021 · 10 comments
Closed
Labels
bug Something isn't working

Comments

@mxmrlt
Copy link

mxmrlt commented Mar 16, 2021

SwaggerUI doesn't work at all while behind a reverse proxy like Traefik even if good HTTP Headers are sent.

contextPath is available but doesn't seem to be used as you can see below

I tried setting this.swaggerConfigUrl and this.apiDocsUrl by appending default urls to the contextPath as we could expect according to the method signatures and it works well behind Traefik.

Is it really an issue that contextPath variable in thoses methods are not used?

@bnasslahsen
Copy link
Contributor

Please read this section:

@mxmrlt
Copy link
Author

mxmrlt commented Mar 16, 2021

@bnasslahsen I did read this section actually.

I tried all of it (version 1.5.6 BTW)

server.forward-headers-strategy=native OR framework
server.use-forward-headers=true

I also added cause I'm using reactive.

@Bean
ForwardedHeaderTransformer forwardedHeaderTransformer() {
    return new ForwardedHeaderTransformer();
}

the contextPath is '/transcodification'

First root call is good with a temporary redirect
Capture d’écran de 2021-03-16 15-35-02

Then redirect to UI with the right contextPath but not the queryParam configUrl
Capture d’écran de 2021-03-16 15-35-08

Then and so we've got a 404
Capture d’écran de 2021-03-16 15-35-17

@bnasslahsen
Copy link
Contributor

@ethali,

You should make sure your proxy sends the correct headers, as described. Make sure your restart your application after the configuration changes.

For example, using Apache 2, configuration:

  • X-Forwarded-Prefix "/custom-path"

If you are still facing this problem: You can set manually the configurl as workaround and test if it's ok.
springdoc.swagger-ui.configUrl = /transcodification/v3/api-docs/swagger-config

If it's working after setting the configUrl manually, this means it's a bug and we can reopen the issue.

@mxmrlt
Copy link
Author

mxmrlt commented Mar 16, 2021

@bnasslahsen

  • X-Forwarded-Prefix "/transcodification" is sent

I set server.forward-headers-strategy=framework wiith the ForwardedHeaderTransformer Bean as mentioned above.

Only redirect to /transcodification/webjars/swagger-ui/index.html is OK.

if I set springdoc.swagger-ui.configUrl = /transcodification/v3/api-docs/swagger-config all is OK about networking but I get PetStore example...

Capture d’écran de 2021-03-16 17-15-48

@bnasslahsen bnasslahsen reopened this Mar 16, 2021
@bnasslahsen
Copy link
Contributor

@ethali,

Can you Provide a Minimal, Reproducible Example - with HelloController that reproduces the problem ?

@bnasslahsen bnasslahsen changed the title contextPath not used while behind a load balancer/reverse proxy webflux: contextPath not used while behind a load balancer/reverse proxy Mar 16, 2021
@mxmrlt
Copy link
Author

mxmrlt commented Mar 17, 2021

@bnasslahsen

OK here's a minimal project that reproduces the problem.
https://github.com/ethali/hello

Sorry if I did something wrong.

@bnasslahsen
Copy link
Contributor

@ethali,

This should be fixed with the latest SNAPSHOT.
You can test it, and if you are still facing other issues you can let me know.

@mxmrlt
Copy link
Author

mxmrlt commented Mar 18, 2021

@bnasslahsen,

Just tested with 1.5.7-SNAPSHOT and it seems to work great behind my Traefik container.

It works with:

just server.forward-headers-strategy=framework set

OR just with bean injected

@Bean
ForwardedHeaderTransformer forwardedHeaderTransformer() {
    return new ForwardedHeaderTransformer();
}

Thank you!

@sergey-volkov-lm
Copy link

For now, you can try springdoc version 1.4.8, it works fine for me.

@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
@evan-qianjh
Copy link

@bnasslahsen Hi. This bug reappears in version 1.6.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants