-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
hosting Swagger UI behind reverse proxy #3192
Comments
Did you try to override the "default" implementation to your own and see if that fixes your issue? |
@jeremyVignelles thanks - how does one recommend going about that? Work around recommendations appreciated! |
Are you looking for this kind of code ? NSwag/samples/WithMiddleware/Sample.AspNetCore21.Nginx/Startup.cs Lines 57 to 80 in b63faa8
|
@jeremyVignelles - well if you mean uncomment the commented code (and make the app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
}); parts etc. |
UseForwardedHeaders seems to be asp.net core thing. not sure what it does and whether you should keep it |
@jeremyVignelles - yes not sure why it's in the sample? So I have modified the code as suggested above, however from an Envoy perspective it does not use the Given my routing per the original post (as app.UseSwaggerUi3(config =>
{
config.TransformToExternalPath = (internalUiRoute, request) =>
{
var externalPath = !request.Headers.ContainsKey("x-envoy-original-path") ? "" :
request.Headers["x-envoy-original-path"].First().Split('/', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
return externalPath + internalUiRoute;
};
}); However this still does not work, and there must be more needed, as it ends up at the default route (
Of note: something is obviously missing to have the Any suggestion given deeper NSwag knowledge how this might be fixed ? @RicoSuter is thee a need to consider if the default implementation based on this documentation (and referenced here) perhaps with some configurability of both the header name used, and how the route is redefined? To confirm using the implementation per the documentation we end up per login with these endpoints being hit
So not working at all. All help greatly appreciated. |
Did you change the code in the document generation settings too? I don't see the point of changing the default handling if :
|
@jeremyVignelles Thanks for the quick turn around... I assume you mean this: app.UseOpenApi(config => config.PostProcess = (document, request) =>
{
if (request.Headers.ContainsKey("X-External-Host"))
{
// Change document server settings to public
document.Host = request.Headers["X-External-Host"].First();
document.BasePath = request.Headers["X-External-Path"].First();
}
}); Just seeing how I'd make this work in my case given above. Well I'd say that NginX/IIS is just a part of the revers proxy universe. Envoy is now part of the AWS AppMesh implementation, so it's hardly "not standard"!. Why have users of NSwag jump though hoops decoding the documentation (and missing elements of swashbuckle). Why do the |
Swagger UI is not the problem. You need to configure whole app to be aware of being behind proxy to have proper host and scheme in http context. Read this first https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-6.0 Now sample code
Having proper values in |
Hi (@jeremyVignelles - pre other thread) - Per this documentation
We're hosting behind an Envoy Mesh Gateway, in a micro services environment. We have public/internet accessing hosts and more importantly internal hosts, that also support the swagger routes such they they are not exposed externally - such that we can use them for diagnostics and testing.
Most of our micro services have a route prefix behind the reverse-proxy, with rewrite rules. we host one of the micro services on the default route without a route prefix (
/
), and all our calls to get to swagger from the other micro services (say/service1/swagger
) are falling back to that (/swagger
).Per the Envoy logging (abbreviated) we get this sequence of calls:
"GET /service1/swagger" -> 127.0.0.1:5012
this correctly routes to the correct micro service"GET /swagger/index.html HTTP/1.1" -> "127.0.0.1:5014"
looses the route...so directs a a different micro service (Note different Port)"GET /swagger/v1/swagger.json -> "127.0.0.1:5014"
as above.Of note that being behind Envoy, and differing from IIS/NginX, due to some other testing it's know that we see an
x-forwarded-for
header. Again note the lower case. Perhaps the default implementation needs to be case insensitive ?The text was updated successfully, but these errors were encountered: