Http: proxy error: dial tcp 127.0.0.1:3030: connect: connection refused

I am using the below repository to set up tyk open source gateway locally, but I am not getting connected with the node js rest API.

In addition, I have tested that the demo API is working fine according to this tutorial, but I am eager to test a simple RESTful application written in node js.

Below is the docker compose file I am using to setup the tyk open source gateway

version: '3.3'
services:
  tyk-gateway:
    image: docker.tyk.io/tyk-gateway/tyk-gateway:v3.2.1
    ports:
      - 8080:8080
    networks:
      - tyk
    volumes:
      - ./tyk.standalone.conf:/opt/tyk-gateway/tyk.conf
      - ./apps:/opt/tyk-gateway/apps
      - ./middleware:/opt/tyk-gateway/middleware
      - ./certs:/opt/tyk-gateway/certs
    environment:
      - TYK_GW_SECRET=foo
    depends_on:
      - tyk-redis
  tyk-redis:
    image: redis:5.0-alpine
    networks:
      - tyk
    ports:
      - 6379:6379
  simple-api:
    build:
      context: .
      dockerfile: ./simple-api/Dockerfile

    volumes:
    - ./simple-api/src/index.js:/var/www/index.js
    - ./simple-api/src/package.json:/var/www/package.json
    - ./simple-api/src/package-lock.json:/var/www/package-lock.json
    networks:
      - tyk
    ports:
      - "3030:3030"

networks:
  tyk:

Create API configuration

{
    "name": "Test API",
    "slug": "test-api",
    "api_id": "1",
    "org_id": "1",
    "use_keyless": true,
    "auth_configs": {
      "authToken": {
        "auth_header_name": "Authorization"
      }
    },
    "definition": {
      "location": "header",
      "key": "x-api-version"
    },
    "version_data": {
      "not_versioned": true,
      "versions": {
        "Default": {
          "name": "Default",
          "use_extended_paths": true
      }
     }
    },
    "proxy": {
      "listen_path": "/test-api/",
      "target_url": "http://127.0.0.1:3030/",
      "strip_listen_path": true
    },
    "active": true
  }
  

Please help me to fix this issue.

Thanks & Regards,
Santosh

Hi @santoshshinde2012, could you share a couple of things.

  1. The result of the health check on the gateway. As a pre-requisite you need to enable health checks in the config file.

image

  1. The gateway debug logs at the time of the request If Redis connection is successful. You can get them from the container considering you are using Docker. You can enable debug logs from the environment variable
    environment:
      - TYK_LOGLEVEL=debug
  1. Your config file and a snippet of how you are calling the API on the gateway
  1. The result of the health check on the gateway. As a pre-requisite, you need to enable health checks in the config file.

  1. The gateway debug logs at the time of the request If Redis connection is successful. You can get them from the container considering you are using Docker. You can enable debug logs from the environment variable

  1. Your config file and a snippet of how you are calling the API on the gateway

@Olu Thank you so much for your response. Do I need to configure the IP address of my REST application when I run the tyk docker image?

That might work but I do not think it is necessary. I think the issue is with the gateway trying to communicate with your simple-api. You could swap your localhost address with the IP address of the host machine running the containers (can be a LAN IP of the machine). You could also replace it with the container name but I am not sure if it would work

1 Like

Thank you so much @Olu for your response. Although I have run the application on a tunnel (with a public IP), I am not able to set it up without a public IP.

I have written this basic article to explain how to set up the open-source version from end to end.

1 Like

Nice article :+1:. If you are still interested, you could use http://host.docker.internal:{PORT_NUMBER} as your target url and it should work.

2 Likes

Hello @santoshshinde2012

We’d like to send you a public thanks for writing your excellent Getting Started guide. Big respect for giving back to the community :metal:

medalgiphy

Here is your virtual medal. Santosh please DM me your address so we can send you some well-deserved Tyk swag

2 Likes

@Andrew Thank you so much for motivating me. It means a lot to me :bowing_man:

1 Like

Thank you so much @Olu, will try your suggestion as well :bowing_man:

I have created a new article because I am facing the same issue

and couldn’t solve it

@Harasisco Thanks for creating a new article.

Your inquiry is being addressed in the topic shared. Please refer to the discussion for further assistance.