首页 > 解决方案 > 响应转换器错误:未找到策略

问题描述

我有以下 gateway.config.yml 文件

http:
  port: 8080
admin:
  port: 9876
apiEndpoints:
  lags:
    path: '/lags/*'
serviceEndpoints:
  lags:
    url: 'http://lags:50001'
policies:
  - response-transformer
  - basic-auth
  - cors
  - expression
  - jwt
  - log
  - oauth2
  - proxy
  - rate-limit
  - verify-auth0-jwt
pipelines:
  lags:
    apiEndpoints:
      - lags
    policies:
      - log:
        - action:
            message: ${req.ip} ${req.method} ${req.originalUrl}
      - rate-limit:
        - action:
            max: 1
            windowMs: 1000
      - jwt:
        - action:
            secretOrPublicKeyFile: ./key/pubKey.pem
            checkCredentialExistence: false
      - response-transformer:
        - action:
            headers:
              add:
                content-type: "'application/json'"
      - verify-auth0-jwt:
        - action:
      - proxy:
        - action:
            serviceEndpoint: lags
            changeOrigin: true

当我运行它时,我得到了这个错误

api-gateway_1  | error: [EG:policy] Could not find policy response-transformer, Please make sure the plugins providing such policy
api-gateway_1  |        is correctly configured in system.config file.
api-gateway_1  | /app/node_modules/express-gateway/lib/policies/index.js:46
api-gateway_1  |       throw new Error('POLICY_NOT_FOUND');
api-gateway_1  |       ^
api-gateway_1  | 
api-gateway_1  | Error: POLICY_NOT_FOUND
api-gateway_1  |     at Policies.resolve (/app/node_modules/express-gateway/lib/policies/index.js:46:13)
api-gateway_1  |     at /app/node_modules/express-gateway/lib/gateway/index.js:72:29
api-gateway_1  |     at Array.forEach (<anonymous>)
api-gateway_1  |     at bootstrap (/app/node_modules/express-gateway/lib/gateway/index.js:71:66)
api-gateway_1  |     at module.exports (/app/node_modules/express-gateway/lib/gateway/index.js:20:39)
api-gateway_1  |     at Main.run (/app/node_modules/express-gateway/lib/index.js:23:43)
api-gateway_1  |     at Object.<anonymous> (/app/server.js:6:4)
api-gateway_1  |     at Module._compile (node:internal/modules/cjs/loader:1101:14)
api-gateway_1  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
api-gateway_1  |     at Module.load (node:internal/modules/cjs/loader:981:32)
api-gateway_1  |     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
api-gateway_1  |     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
api-gateway_1  |     at node:internal/main/run_main_module:17:47

它在 docker 容器中运行。我在 package.json 中定义了最新版本的 express-gateway。

请看下面

{
  "name": "loc8r-api-gateway",
  "description": "Express Gateway Instance Bootstraped from Command Line",
  "repository": {},
  "license": "UNLICENSED",
  "version": "1.0.0",
  "main": "server.js",
  "dependencies": {
    "express-gateway": "^1.16.11",
    "express-jwt": "^6.0.0",
    "express-jwt-authz": "^2.4.1",
    "jsonwebtoken": "^8.5.1",
    "jwks-rsa": "^2.0.4"
  }
}

标签: javascriptnode.jsexpressapi-gatewayexpress-gateway

解决方案


推荐阅读