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

Regression in v4.0.0 when hosted behind a path rewriting reverse proxy #162

Closed
2 tasks done
Hornwitser opened this issue Jul 18, 2024 · 3 comments
Closed
2 tasks done

Comments

@Hornwitser
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the regression has not already been reported

Last working version

3.1.0

Stopped working in version

4.0.0

Node.js version

18.x

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Debian 11

💥 Regression Report

When a reverse proxy rewrites the URL path before forwarding the request to the Node.js server running swagger-ui the interface gets confused and the Swagger UI becomes inoperable.

For example when a GET /api/documentation request is remapped to GET /documentation before being passed on to swagger-ui v4.0.0 the resulting html page it responds to contains resources links to /documentation/static/<resource>, which will not load as the server hosts these resources under /api/documentation/static/<resource>. Trying to access /api/documentation/static/index.html which used to work causes swagger-ui to redirect the browser to /documentation.

In swagger-ui v3.1.0 all links were relative. A GET /api/documentation request remapped to GET /documentation would correctly reply with a relative redirect to ./documentation/static/index.html sending the browser to /api/documentation/static/index.html. This page only used relative links of the form ./<resource> so it wasn't sensitive to the path prefix being remapped.

Steps to Reproduce

Configure a reverse proxy in front of swagger-ui, for example with an Apache ProxyPass directive.

<Location /api/>
    ProxyPass http://localhost:3000/
</Location>

Observe that in v3.1.0 you can access the swagger UI under /api/documentation, while in v4.0.0 it doesn't work at all.

Expected Behavior

Upgrading from 3.1.0 shouldn't cause the swagger UI to break when hosted behind a reverse proxy where the path has been rewritten. Or alternatively, this breakage/new requirement should be clearly documented.

@mcollina
Copy link
Member

This wasn't expected, but I guess we should have caught it.

Would you like to send a PR to fix?

@mcollina
Copy link
Member

cc @jdhollander

@jdhollander
Copy link
Contributor

@mcollina Thanks for mentioning me, I've made a fix, see what you think...

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

Successfully merging a pull request may close this issue.

3 participants