使用 istio 虚拟服务通过 Swagger .NET Core 在 Kubernetes 上部署微服务

问题描述 投票:0回答:0

招摇的文档不能很好地加载虚拟服务,但如果我在没有虚拟服务的情况下测试它,它在 kubernetes 中工作正常。 El nuget del swagger es MMLib.SwaggerForOcelot.

虚拟服务

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

招摇配置

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");
});

额外设置

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

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

asp.net-core-webapi istio swashbuckle ocelot
© www.soinside.com 2019 - 2024. All rights reserved.