如何在Kong Api-Gateway返回静态响应

发布于 2025-02-06 04:59:51 字数 1094 浏览 4 评论 0 原文

我在其db-never模式下使用了kong api-gateway

结果,

_format_version: "2.1"
_transform: true

services:
  - name: service1
    url: http://service1:port/sample-path
    routes:
      - name: service1
        methods:
          - GET
        paths:
          - /service1/sample-path
        strip_path: true

,我有一个kong.yaml文件,如下所示:如您所见,API-GATEWAY DISPATCHES来自/service>/service>/service1/sample-path http:// service1:port/sample-path 的API-GATWAY的端点>

> /代码> API-GATEWAWE的端点,它加载YAML或JSON文件并将其作为响应返回。

在行动中,我正在寻找一种返回静态响应而不是派遣请求的方法?

知道该怎么做吗?

伪代码

_format_version: "2.1"
_transform: true

services:
  - name: service1
    url: http://service1:port/sample-path
    routes:
      - name: service1
        methods:
          - GET
        paths:
          - /service1/sample-path
        strip_path: true
  - name: oas
    url: STATIC YAML OR JSON FILE
    routes:
      - name: oas
        methods:
          - GET
        paths:
          - /oas
        strip_path: true

I am using kong API-gateway in its DB-Less mode

as a result, I have a kong.yaml file as below:

_format_version: "2.1"
_transform: true

services:
  - name: service1
    url: http://service1:port/sample-path
    routes:
      - name: service1
        methods:
          - GET
        paths:
          - /service1/sample-path
        strip_path: true

As you see, the api-gateway dispatches requests from /service1/sample-path endpoint of api-gatway to http://service1:port/sample-path

I am looking for a way to add a new service such that when a request is sent to /oas endpoint of api-gateway, it loads a yaml or json file and return that as the response.

In action, I am looking for a way to return a static response instead of dispatching the request?

Any idea how to do this?

pseudo code

_format_version: "2.1"
_transform: true

services:
  - name: service1
    url: http://service1:port/sample-path
    routes:
      - name: service1
        methods:
          - GET
        paths:
          - /service1/sample-path
        strip_path: true
  - name: oas
    url: STATIC YAML OR JSON FILE
    routes:
      - name: oas
        methods:
          - GET
        paths:
          - /oas
        strip_path: true

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

养猫人 2025-02-13 04:59:51

您可以使用插件

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文