0

The swagger doc doesn't load well with the virtual service but if I test it without the virtual service, it works fine in kubernetes. El nuget del swagger es MMLib.SwaggerForOcelot.

Virtual Service

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: gateway-acces-virtualservice
spec:
  hosts:
  - "*"
  gateways:
  - my-gateway # el nombre del gateway creado anteriormente
  http:
  - match:
    - uri:
        prefix: /gateway-acces
    rewrite:
      uri: "/gateway-acces/swagger/index.html"
    route:
    - destination:
        host: gateway-acces # el nombre del servicio creado anteriormente
        port:
          number: 7005 # el puerto del servicio

Swagger Config

services.AddSwaggerGen(c => {
  c.SwaggerDoc("v1", new OpenApiInfo {
    Title = "SitesGatewayAccess", Version = "v1"
  });
  c.DocumentFilter < SwaggerDocFilter > ();
});

app.UseSwagger();

string pkgUrl = "https://unpkg.com/swagger-ui-dist@";
string swaggerVersion = "4.15.5";

app.UseSwaggerForOcelotUI(c => {
  c.DownstreamSwaggerEndPointBasePath = "/gateway-acces/docs";
  c.PathToSwaggerGenerator = "/gateway-acces/docs";
}, optionsSwagger => {
  optionsSwagger.RoutePrefix = "gateway-acces/swagger";
  optionsSwagger.HeadContent =
    $ "<link rel=\"stylesheet\" type=\"text/css\" " +
    $ "href=\"{pkgUrl}{swaggerVersion}/swagger-ui.css\" />";
  optionsSwagger.InjectStylesheet($"{pkgUrl}{swaggerVersion}/swagger-ui.css", "text/css");
  optionsSwagger.InjectJavascript($"{pkgUrl}{swaggerVersion}/swagger-ui-standalone-preset.js", "text/javascript");
  optionsSwagger.InjectJavascript($"{pkgUrl}{swaggerVersion}/swagger-ui-bundle.js", "text/javascript");
});

extra settings

app.Use((context, next) => {
  context.Request.PathBase = new PathString("/gateway-acces");
  return next.Invoke();
});

app.UseStaticFiles();
app.UseForwardedHeaders();

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

0 Answers0