title: Express-Gateway - 502 Bad Gateway with docker-compose Nodejs Microservices Architecture
body: <p>I've been trying to do a NodeJS Microservices Architecture using Docker.</p>
  <p>I currently have 2 services : Auth API et Users CRUD API. Now my goal is to setup a Gateway using Express-Gateway.</p>
  <p>I followed many tutorials on the web to try to set it up but whenever I try to make a request to the gateway (acting like a proxy) it sends a 502 bad gateway response..</p>
  <p><a href="https://i.stack.imgur.com/tdnlx.png" rel="nofollow noreferrer">response error in PostMan </a></p>
  <p><a href="https://i.stack.imgur.com/n2Kbt.png" rel="nofollow noreferrer">error in express-gateway logs</a></p>
  <p>My docker-compose.yml :</p>
  <pre><code>networks:
    goodfood:
      driver: bridge
  
  services:
  
    gateway:
      container_name: gateway
      image: 'node:17-alpine'
      # env_file:
      #   - ./gateway/.env
      working_dir: /usr/src/app
      volumes:
        - './gateway:/usr/src/app'
      command: npm run dev
      ports:
        - '8080:8080'
      networks:
        - goodfood
  
    auth:
      container_name: auth
      image: 'node:17-alpine'
      # env_file:
      #   - ./auth/.env
      working_dir: /usr/src/app
      volumes:
        - './auth:/usr/src/app'
      command: npm run dev
      ports:
        - '3002:3000'
      networks:
        - goodfood
  
    users:
      container_name: users
      image: 'node:17-alpine'
      env_file:
        - ./users/api/.env
      working_dir: /usr/src/app
      volumes:
        - './users/api:/usr/src/app'
      command: npm run dev
      ports:
        - '3001:3000'
      networks:
        - goodfood
      depends_on:
        - users-db
  
    users-db:
      container_name: users-db
      image: postgres
      restart: always
      env_file:
        - ./users/db/.env
      volumes:
        - './users/db/data:/var/lib/postgresql/data'
        - './users/db/scripts/init.sql:/docker-entrypoint-initdb.d/init.sql'
      ports:
        - '5432:5432'
      networks:
        - goodfood
  
    users-adminer:
      container_name: users-adminer
      restart: unless-stopped
      image: adminer
      ports:
        - '8181:8080'
      networks:
        - goodfood
      depends_on:
        - users-db
  </code></pre>
  <p>And my gateway.config.yml :</p>
  <pre><code>http:
    port: 8080
  admin:
    port: 9876
    host: localhost
  
  apiEndpoints:
    users:
      path: ['/users', '/users/*']
    auth:
      path: ['/auth', '/auth/*']
  
  serviceEndpoints:
    users:
      url: 'http://users:3001'
    auth:
      url: 'http://auth:3002'
  
  policies:
    - log
    - proxy
    # - jwt
    # - request-transformer
  
  pipelines:
    authPipeline:
      apiEndpoints:
        - auth
      policies:
        - log:
            action:
              message: 'auth ${req.method}'
        - proxy:
            - action:
                serviceEndpoint: auth
                changeOrigin: true
  
    usersPipeline:
      apiEndpoints:
        - users
      policies:
        - log:
            action:
              message: 'users ${req.method}'
        - proxy:
            - action:
                serviceEndpoint: users
                changeOrigin: true
        # - jwt:
        #     action:
        #       secretOrPublicKey: 'goodfood'
        #       checkCredentialExistence: false
        # - request-transformer:
        #     action:
        #       body:
        #         add:
        #           user: req.user
  </code></pre>
  <p>If you need further details there's a github repo : <a href="https://github.com/KIVTVN/goodfood/tree/master" rel="nofollow noreferrer">https://github.com/KIVTVN/goodfood/tree/master</a></p>