微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

招摇加豹猫

如何解决招摇加豹猫

我正在尝试使用 ocelot 和 swagger (https://github.com/Burgyn/MMLib.SwaggerForOcelot) 来实现网关。我能够在我的本地主机中很好地配置一切,现在我需要将我的解决方案部署到 kubernetes,但是,因为有一些功能是并行开发的,我被要求将我的解决方案部署在一个子目录中,就像这样。>

  • https://domain/Feature1/gateway1
  • https://domain/Feature2/gateway2 ...

他们不知道按功能拥有子域。

我的配置有效,但 swagger UI 有问题,因为测试路径是这样映射的。

https://domain/api/service/method

但我需要类似的东西

https://domain/Feature1/api/service/method

可以吗?

解决方法

我不确定是否有帮助,但 MMLib.SwaggerForOcelot 支持虚拟目录。 Please try this

,

也许它可以对某人有所帮助,这是我可以使此设置正常工作的唯一方法。

在以下位置访问 swagger 文档: https://domain/gatewayfeature1

以及 api: https://domain/apisfeature1

对于另一个功能也是如此。

文档 https://domain/gatewayfeature2

API https://domain/apisfeature2

我使用 nginx 作为反向代理,使用 ocelot 作为网关和 GKE 集群中的 api。

我结束使用的入口 yaml 是这个特性,“apifeature1”,“apifeature2”,...

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/use-regex: "true"
  name: test
  namespace: default
spec:
  rules:
  - host: testdomain
    http:
      paths:
      - backend:
          serviceName: gateway-feature1
          servicePort: 80
        path: /docsfeature1/(.*)
      - backend:
          serviceName: gateway-feature1
          servicePort: 80
        path: /(apifeature1/.*)

Ocelot 配置按功能“apifeature1”、“apifeature2”、...

在这种情况下,我从配置中读取功能名称,因此 ocelot 配置像本示例一样结束。

{
  "UpstreamPathTemplate": "/apifeature1/api/controller/{everything}","UpstreamHttpMethod": [ "Get","Post" ],"DownstreamPathTemplate": "/{everything}","DownstreamScheme": "http","DownstreamHostAndPorts": [
    {
      "Host": "apifeature1","Port": "80"
    }
  ],"SwaggerKey": "api"
},

以及按功能划分的网关。

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

.
.
.

app.UseSwaggerForOcelotUI(c =>
{
    c.DownstreamSwaggerEndPointBasePath = "/apifeature1/swagger/docs";
    c.PathToSwaggerGenerator = "/apifeature1/swagger/docs";
    c.DocumentTitle = "DOCUMENT";
});

它有效,但是,我认为它可以改进。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。