在我的 Node 系统中,我有一个服务器公开了一些 API,可以通过 Express Gateway 访问。req.body
根据使用我的 API 的应用程序,我想强制在 中添加一些参数。
为此,我使用个性化scope
价值。例如,我有 App1 和 App2(及其凭据)使用我的 API。因此,在例如凭据中,我将范围添加app1
到 App1 凭据和app2
App2 凭据的范围。
在gateway.config.yml
我写的文件中:
...
- request-transformer:
- condition:
name: allOf
conditions:
-
name: regexpmatch
match: ^/user/signup?(.*)$
-
name: expression
expression: "apiEndpoint.scopes.indexOf('app1')>=0"
- action:
body:
add:
custom_field: "'app1'"
- condition:
name: allOf
conditions:
-
name: regexpmatch
match: ^/user/signup?(.*)$
-
name: expression
expression: "apiEndpoint.scopes.indexOf('app2')>=0"
- action:
body:
add:
custom_field: "'app2'"
但我得到这个错误:
error: Policy request-transformer params validation failed:
data should have required property '.headers',
data should have required property '.body',
data should match some schema in anyOf
(node:17362) UnhandledPromiseRejectionWarning: Error: POLICY_PARAMS_VALIDATION_FAILED
=============
实际看 JSON 转换action
,request-transformer
. 缩进不好。