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.

But when I logging request header and request body from shop service

 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!

Upvotes: 0

Views: 466

Answers (1)

James McLeod
James McLeod

Reputation: 2406

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

Upvotes: 0

Related Questions