dockerdocker-composeexpress-gateway

Express gateway always return Bad Gateway when I run with docker-compose


I tried to use Express Gateway with Docker as a Container for each microservice. So far it has been very good at local testing. There was a problem using the Docker by implementing EG. I don't know where the problem is. There is no complete description at LOG_LEVEL = debug. Previously I used the docker without EG and then communicating with other microservices just fine. Please help.

gateway.config.yml

http:
  port: 8080
admin:
  port: 9876
apiEndpoints:
  authAPI:
    host: '*' # i tried with egateway, localhost, 127.0.0.1 but still not working
    paths:
      - '/users/signin'
      - '/users/signup'
      - '/users/oauth/facebook'
      - '/users/auth/google'
      - '/users/auth/google/callback'
      - '/users/secret'
      - '/users/get-user-google'
      - '/dashboard'
      - '/test'
  crudAPI:
    host: '*'
    paths:
      - '/users/get-user-data'
      - '/users/delete-user-data'
      - '/users/add-user-data'
      - '/users/get-one-user-data/*'
      - '/users/update-user-data'
      - '/users/update-pass-user-data'
serviceEndpoints:
  authService:
    url: 'http://localhost:3003'
  crudService:
    url: 'http://localhost:3004'
policies:
  - log
  - proxy
  - jwt
  - cors
  - jwt-custom1
pipelines:
  crud:
    apiEndpoints:
      - crudAPI
    policies:
      - cors:
          - action:
              origin: '*'
              methods: 'GET, POST, PUT, DELETE'
              allowedHeaders: 'X-Requested-With,content-type,Authorization'
              credentials: true
      - proxy:
          - action:
              serviceEndpoint: crudService
  auth:
    apiEndpoints:
      - authAPI
    policies:
      - proxy:
          - action:
              serviceEndpoint: authService


docker-compose.yml

version: '3'

services:

  egateway:
    hostname: egateway
    container_name: egateway
    build: './test-eg2'
    ports: 
      - "8080:8080"
    depends_on: 
      - mongo
    environment: 
      - LOG_LEVEL=debug

  api-auth:
    container_name: api-auth
    build: './api-auth'
    ports: 
      - "3003:3003"
    links: 
      - mongo
      - egateway

  api-crud:
    container_name: api-crud
    build: './api-crud'
    ports: 
      - "3004:3004"
    links: 
      - mongo
      - egateway

  mongo:
    container_name: mongo-dbx
    image: mongo
    ports: 
      - "27017:27017"

Results from log level = debug enter image description here

I need your help. Thank you for reviewing this issue.


Solution

  • Your URL for the auth-service and crud-service shouldn't be localhost. It should be:

    serviceEndpoints:
      authService:
        url: 'http://api-auth:3003'
      crudService:
        url: 'http://api-crud:3004'
    

    api-auth and api-crud would be the hostnames for those 2 containers in your docker-compose network.