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 behind Service Fabric Reverse Proxy #427

Closed
ghelyar opened this issue Jun 16, 2017 · 10 comments
Closed

Swagger UI behind Service Fabric Reverse Proxy #427

ghelyar opened this issue Jun 16, 2017 · 10 comments

Comments

@ghelyar
Copy link

ghelyar commented Jun 16, 2017

I have a Service Fabric stateless service hosted in Azure, using Service Fabric's Reverse Proxy for access.

The working swagger.json URL looks like this:
http://clustername.westeurope.cloudapp.azure.com/AppName/ServiceName/swagger/v1/swagger.json

However, when I try to load the swagger UI at
http://clustername.westeurope.cloudapp.azure.com/AppName/ServiceName/swagger/
it 301 redirects to the internal path of the node handling the request
http://clustername.westeurope.cloudapp.azure.com/01234567-0123-0123-0123-0123456789ab/012345678901234567/swagger/
which is not publicly accessible.

If I RDP onto the node, swagger UI on localhost does work:
http://localhost:50874/01234567-0123-0123-0123-0123456789ab/012345678901234567/swagger

My startup uses the following configuration to find the json file relative to the swagger UI, which also works when not behind the reverse proxy:
app.UseSwagger().UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "Service V1"));

The only x-forwarded headers I have available are:
Host: 10.0.0.4:50874
X-Forwarded-For: 123.123.123.123
X-Forwarded-Host: clustername.westeurope.cloudapp.azure.com
X-Forwarded-Proto: http

It seems that in 4.0 this was solved using ResolveBasePathUsing and in 5.0 this was solved using RootUrl. How can I solve this in Swashbuckle.AspNetCore? I have tried the PreSerializeFilter suggestion from Issue #68 with no luck.

@eric-davis
Copy link

I am running into a similar situation running behind HAProxy and utilizing URL rewriting features and can't figure out to force Swashbuckle.AspNetCore to keep the original request URL structure.

@kavyako
Copy link

kavyako commented Jul 12, 2017

I tried a couple of config options but could not get Swagger UI working behind a reverse proxy. Appreciate any guidance on how to set the configs such that Swagger UI loads and can make requests to the service (Try It out options) correctly with reverse proxies.

@kierenj
Copy link

kierenj commented Jul 24, 2017

I'm also looking for the "new" RootUrl. I have everything working with an IIS-based reverse proxy, apart from this bit!

@JDL440
Copy link

JDL440 commented Sep 15, 2017

I was able to make this work by seeting the basePath like this:
.UseSwagger(c =>
{
c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.BasePath = "/MyServiceApp/MyService");
})

@domaindrivendev
Copy link
Owner

See my comments here - #380 (comment)

Easiest way to support reverse proxies!

@ghelyar
Copy link
Author

ghelyar commented Mar 20, 2018

Please re-read the original post then reopen and fix this. This is already using a relative path. It finds the JSON file but then 301 redirects to an internal IP address, which is not available from outside the reverse proxy.

@domaindrivendev
Copy link
Owner

Fair enough - there's a couple of issues mixed up in this one. @ghelyar - this being FREE n open source n all, perhaps you could dig a little deeper and propose a potential fix 😉

@domaindrivendev
Copy link
Owner

Dup of #662

I'm going to close this in favor of the above duplicate because it's detailing of the problem is a little clearer.

@domaindrivendev
Copy link
Owner

@ghelyar - which version of Swashbuckle are you using

@wswind
Copy link

wswind commented Apr 29, 2020

I used relative URL to fix this, see this comment:
#380 (comment)

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

No branches or pull requests

7 participants