0

问题总结:

我有一个在 192.168.23.231 上运行的 k3s 实例。端口 30001 映射到我构建的 REST API 应用程序。端口 31166 映射到 Krakend。当我在浏览器中输入http://192.168.23.231:31166/datamanager/hello时,我收到一条 HTTP 500 错误消息,指出“http://192.168.23.231 当前无法处理此请求”。

如果我浏览到http://192.168.23.231:30001/hello,我会按预期得到“Hello World”,所以我知道 REST API 运行正常。我的期望是 Krakend 端点会返回同样的东西,但事实并非如此。

这是我的 krakend.json 配置文件的摘录,显示了端点配置:

"endpoints": [
    {
      "endpoint": "/datamanager/hello",
      "method": "GET",
      "output_encoding": "string",
      "extra_config": {},
      "backend": [
        {
          "url_pattern": "/hello",
          "encoding": "json",
          "sd": "static",
          "method": "GET",
          "extra_config": {},
          "host": [
            "http://datamanager.my-test.svc.cluster.local:4567"
          ],
          "disable_host_sanitize": false
        }
      ]
    },

除非我弄错了,否则192.168.23.231:31166/datamanager/hello应该datamanager.my-test.svc.cluster.local:4567/hello由 Krakend 路由到。

我试图用谷歌搜索,但结果似乎与我的问题不符。

4

1 回答 1

0

The 500 error is the default status code when KrakenD is unable to process your backend response.

In the KrakenD configuration you are showing, we can see that you are telling KrakenD that the response from your backend (the encoding) is a JSON object, but instead your backend returns a string Hello World, which is not a JSON.

The KrakenD logs will show something like:

Error #01: invalid character 'H' looking for beginning of value

And that H is from Hello World.

If you'd like to consume strings instead of json use string as the value of encoding. If you want the response as is from your backend, use no-op both in encoding and output_encoding

于 2021-12-21T08:44:13.573 回答