Express-Gateway设置授权后响应错误

Express-Gateway response error after setting authorization

我尝试在请求 header 中设置我的授权密钥 (key-auth) 时收到错误 404。我确定我的密钥没有任何问题,因为如果我不设置它,禁止状态将 return.

在设置任何凭据之前:

$ curl http://localhost:8080/ip

将return:

{
  "origin": "5.116.28.133"
}

创建 key-auth 凭据后:

$ curl -H "Authorization: apiKey ${keyId}:${keySecret}" http://localhost:8080/ip

将return:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /ip</pre>
</body>
</html>

这是我的网关配置:

http:
  port: 8080
admin:
  port: 9876
  hostname: localhost
apiEndpoints:
  api:
    host: localhost
    paths: '/ip'
serviceEndpoints:
  httpbin:
    url: 'https://httpbin.org'
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
pipelines:
  - name: default
    apiEndpoints:
      - api
    policies:
    - key-auth:
      - proxy:
          - action:
              serviceEndpoint: httpbin 
              changeOrigin: true

有谁知道为什么会出现这个问题?

http://www.express-gateway.io/

中找到有关 express-gateway 的更多信息

尝试从配置文件中 policies: 下的 key-auth 中删除连字符 - 这对我有用。它应该只是 keyauth.

应该是key-auth 问题是缩进

- key-auth:
       - proxy:

它必须在一层

基本上这是一个数组:

policies: [{
    'key-auth':null
    },{
    proxy:{ ... }   
}]

这将解决问题。