Reputation: 21
Express gateway always return Bad Gateway when I run with docker-compose or docker I am trying to build a MERN stack application using the NodeJS and microservice architecture and i have completed the project and Dockerized and while I am trying to run the API gateway and the user service it always returns the Bad gateway error
here is my gateway.config.yml
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
api:
host: localhost
paths: '/ip'
user:
host: localhost
paths: '/user/*'
gig:
host: localhost
paths: ['/gig', '/gig/*']
message:
host: localhost
paths: ['/message', '/message/*']
order:
host: localhost
paths: ['/order', '/order/*']
serviceEndpoints:
httpbin:
url: 'https://httpbin.org'
userService:
url: 'http://user-service:8001'
gigService:
url: 'http://gig-service:8002'
messageService:
url: 'http://message-service:8004'
orderService:
url: 'http://order-service:8003'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
default:
apiEndpoints:
- api
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: httpbin
changeOrigin: true
userPipeline:
apiEndpoints:
- user
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: userService
changeOrigin: true
gigPipeline:
apiEndpoints:
- gig
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: gigService
changeOrigin: true
messagePipeline:
apiEndpoints:
- message
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: messageService
changeOrigin: true
orderPipeline:
apiEndpoints:
- order
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: orderService
changeOrigin: true
And this is my docker compose file
version: '3.8'
services:
api-service:
image: aswanth600/api:latest
container_name: api-container
ports:
- "8080:8080"
networks:
- my-network
user-service:
image: aswanth600/user:latest
container_name: user-container
ports:
- "8001:8001"
networks:
- my-network
order-service:
image: aswanth600/order:latest
container_name: order-container
ports:
- "8003:8003"
networks:
- my-network
gig-service:
image: aswanth600/gig:latest
container_name: gig-container
ports:
- "8002:8002"
networks:
- my-network
message-service:
image: aswanth600/message:latest
container_name: message-container
ports:
- "8004:8004"
networks:
- my-network
networks:
my-network:
driver: bridge
then my docker file of user service is
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
Upvotes: 0
Views: 77
Reputation: 21
I changed the localhost entries to use the compose service name instead then it worked
gateway.config
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
api:
host: api-service
paths: '/ip'
user:
host: user-service
paths: '/user/*'
gig:
host: gig-service
paths: ['/gig', '/gig/*']
message:
host: message-service
paths: ['/message', '/message/*']
order:
host: order-service
paths: ['/order', '/order/*']
serviceEndpoints:
httpbin:
url: 'https://httpbin.org'
userService:
url: 'http://user-service:8001'
gigService:
url: 'http://gig-service:8002'
messageService:
url: 'http://message-service:8004'
orderService:
url: 'http://order-service:8003'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
default:
apiEndpoints:
- api
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: httpbin
changeOrigin: true
userPipeline:
apiEndpoints:
- user
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: userService
changeOrigin: true
gigPipeline:
apiEndpoints:
- gig
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: gigService
changeOrigin: true
messagePipeline:
apiEndpoints:
- message
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: messageService
changeOrigin: true
orderPipeline:
apiEndpoints:
- order
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: orderService
changeOrigin: true
Upvotes: -1