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

Unable to use set dynamic base-path (i.e. when using a reverse proxy) #1617

Closed
ramondeklein opened this issue Apr 8, 2020 · 2 comments
Closed

Comments

@ramondeklein
Copy link

The pre-v5.0.0 versions os Swashbuckle.AspNetCore allowed to set the base-path dynamically using a preserialize filter. This allowed to generate the proper paths behind a reverse-proxy, by doing this:

app.UseSwagger(options =>
{
    options.PreSerializeFilters.Add((doc, request) => doc.BasePath = request.Headers["X-Forwarded-Path"]);
});

From v5.0.0 the filter gets an OpenApiDocument instead of a SwaggerDocument and it doesn't have a base-path property. Is there an alternative to enable this functionality?

I have a variable prefix, because my reverse-proxy that allows to access a variety of devices. When accessing the device directly, I can access my API via /api/v1/..., but when using the reverse-proxy I have /device//api/v1/.... I would also like to access the Swagger UI via /device//swagger.

@domaindrivendev
Copy link
Owner

In Swagger/OpenAPI v3 the structure of the doc has changed a bit. The path has moved into the servers property. Take a look a the following readme section for some inspiration:

https://github.com/domaindrivendev/Swashbuckle.AspNetCore#modify-swagger-with-request-context

@ramondeklein
Copy link
Author

That was exactly what I was looking for. Thanks for your support!

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

2 participants