我编写了一个简单的 krakend.json 配置来配置我的端点。此配置调用 Lua 脚本,目前它仅打印正文响应。
{
"version": 2,
"extra_config": {
"github_com/devopsfaith/krakend-gologging": {
"level": "DEBUG",
"prefix": "[KRAKEND]",
"syslog": false,
"stdout": true
},
"github_com/devopsfaith/krakend-metrics": {
"collection_time": "60s",
"proxy_disabled": false,
"router_disabled": false,
"backend_disabled": false,
"endpoint_disabled": false,
"listen_address": ":8090"
}
},
"timeout": "3000ms",
"cache_ttl": "300s",
"output_encoding": "json",
"name": "myregistrydomain.com",
"endpoints": [
{
"endpoint": "/models/{group-id}",
"method": "GET",
"output_encoding": "json",
"headers_to_pass": [
"Authorization",
"Content-Type"
],
"backend": [
{
"url_pattern": "myregistrydomain/get-models-by-group/group-id/{group-id}",
"timeout": "10s",
"encoding": "no-op",
"sd": "static",
"host": ["myregistrydomain"],
"disable_host_sanitize": "false",
"extra_config": {
"github.com/devopsfaith/krakend/http": {
"return_error_details": "backend_models"
},
"github.com/devopsfaith/krakend-lua/proxy/backend": {
"sources": ["file1.lua"],
"post": "check(response);",
"live": true,
"allow_open_libs": true,
"skip_next": false
}
}
}
],
"querystring_params": [
"{group-id}"
]
}
]
}
调用的 Lua 函数是:
function check(response)
print("**")
local r = response.load()
print(r:body())
end
目前打印正文工作正常,我可以看到所有的 json 响应。但是在我的邮递员请求中,我看到一个空的正文响应。我只使用 Lua 函数来检查正文响应是否包含字符串“error”
我的主要问题是为什么在日志上我可以在邮递员中看到身体反应,而不是我的身体是空的?