简体   繁体   English

Express Gateway,请求转换器未将参数添加到正文和 header

[英]Express Gateway, Request transformer not adding parameters to body and header

I want to add parameters to my express gateway,我想向我的快速网关添加参数,

I followed official documentation.我遵循了官方文档。 So my pipeline like that:所以我的管道是这样的:

- name: shop
    apiEndpoints:
      - shop
    policies:
      - proxy:
          - action:
              serviceEndpoint: shopsrv
              changeOrigin: true
      - request-transformer:
        - action:
            body:
              add:
                hello: "'world'"
            headers:
              add:
                r-test: "'header value'"

When I send request to express-gateway/shop service, gateway working without any errors.当我向 express-gateway/shop 服务发送请求时,网关正常工作。

But when I logging request header and request body from shop service但是当我记录请求 header 并从商店服务请求正文时

 req.body : 

 {}
 -----------------

 req.headers : 
 {
   connection: 'upgrade',
   host: 'ec2-54-245-43-241.us-west-2.compute.amazonaws.com',
   'accept-encoding': 'gzip, deflate, br',
   'postman-token': '031920ee-c3e9-4b2f-9464-2e2c1edb3c41',
   accept: '*/*',
   'user-agent': 'PostmanRuntime/7.28.4',
   'eg-request-id': '0hPlQg2jp7ar700zvniG2P'
 }

Why I cannot add any parameters to request?为什么我不能在请求中添加任何参数? Where is the problem?问题出在哪里? Please help!请帮忙!

The documentation for the proxy policy states that the proxy policy must come last;代理策略的文档说明代理策略必须排在最后; you need to reorder your pipeline to conform to this:您需要重新排序管道以符合以下要求:

- name: shop
    apiEndpoints:
      - shop
    policies:
      - request-transformer:
        - action:
            body:
              add:
                hello: "'world'"
            headers:
              add:
                r-test: "'header value'"
      - proxy:
          - action:
              serviceEndpoint: shopsrv
              changeOrigin: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM