question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get express-gateway to work with docker compose

See original GitHub issue

Hi,

I am dealing with the following scenario:

  • I have an authentication API
  • I have an API that connects to a database
  • I have an express-gateway API to handle rate limiting to the database API

The logic is as follows: go to localhost:3000/login (auth-api), login using Auth0, the user is then redirected to the gateway at localhost:8081, the gateway then rate limits and proxies the request to localhost:8000/path/to/data (database API)

Everything works correctly locally. However, now that I am trying to tie everything together using Docker compose. I keep receiving a Bad Gateway error when the gateway is supposed to redirect to the database API. I have included the code that redirects to the gateway, the docker-compose.yml file and the gateway.config.yml file to provide more context.

Database API Redirect

res.redirect('http://gateway:8081/path/to/data?token=' + req.query.code);

Gateway Config File

admin:
  port: 9876
  hostname: localhost
http:
  port: 8081
apiEndpoints:
  orders:
    host: 'gateway' # I have also tried to make this *, localhost and datasets-api and I have removed it completely
    paths:
      - '/path/to/data'
      # - '/'
      # - '*'
serviceEndpoints:
  orders:
    url:  'http://datasets-api:8000' # I have also tried to make this localhost
policies:
  - proxy
  - rate-limit
  - expression
pipelines:
  orders:
    apiEndpoints:
      - orders
    policies:
      - expression:
        - action:
            jscode: "
            "
      - rate-limit:
        - action:
            max: 5
            windowMs: 60000
      - proxy:
          - action:
              serviceEndpoint: orders
              changeOrigin: true # I have also tried this as false

Docker Compose File

version: '3'
services:
  dw-db:
    image: "centos/postgresql-95-centos7"
    environment:
      - POSTGRESQL_USER=admin
      - POSTGRESQL_PASSWORD=password
      - POSTGRESQL_DATABASE=db
    ports:
      - "6000:5432"
  datasets-api:
    build: "./datasets"
    hostname: datasets-api
    ports:
      - "8000:8000"
    environment:
      - HOSTNAME=datasets-api
      - CONFIG_PATH=/usr/src/app/server/config/config.json
    volumes:
      - $PWD/datasets:/usr/src/app
    depends_on:
      - dw-db
    links:
      - dw-db
    tty: true
  gateway:
    build: "./gateway"
    hostname: gateway
    environment:
      - HOSTNAME=gateway
    ports:
      - "8081:8081"
      - "9876:9876"
    depends_on:
      - datasets-api
    links:
      - datasets-api

  auth-api:
    build: "./gateway/auth-api"
    hostname: auth-api
    ports:
      - "3000:3000"
    environment:
      - HOSTNAME=auth-api
      - SERVICE_ENDPOINT=http://gateway:8081 # I have also tried to make this localhost but it makes no difference
    links:
      - gateway
    depends_on:
      - gateway

I have also submitted the issue on Gitter. Please could someone assist me with this?

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
fabiosoftcommented, Nov 1, 2018

Removed all hostnames and works perfectly! 👍

0reactions
EdwinSilvaDKcommented, Mar 10, 2020

I have the same issue but in swam mode ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express gateway always return Bad Gateway ... - Stack Overflow
I tried to use Express Gateway with Docker as a Container for each microservice. So far it has been very good at local...
Read more >
Express gateway always return Bad Gateway when I run with ...
Coding example for the question Express gateway always return Bad Gateway when I run with docker-compose-docker.
Read more >
Setting Default Gateway to a container - Compose
I'm trying to create a vpn container that acts as a gateway for other container to use. My docker-compose.yml is version: '2' services: ......
Read more >
ExpressGateway/express-gateway - Gitter
I'm using express-gateway with docker and it's working with the httpbin example. ... I am getting same error as @aneesh-rastogi but i cannot...
Read more >
Express Gateway 1.7.0 - Lucky 7
In case you have not worked with environment variables in the past: ... If you're already familiar with syntax of Docker Compose YAML...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found