Swagger UI behind Service Fabric Reverse Proxy
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:10 (4 by maintainers)
I was able to make this work by seeting the basePath like this: .UseSwagger(c => { c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.BasePath = “/MyServiceApp/MyService”); })
I used relative URL to fix this, see this comment: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/380#issuecomment-374711180