Skip to content

agungdwiprasetyo/reverse-proxy

Repository files navigation

Pengendali API (Reverse proxy for API Gateway)

Build Status codecov golang

Coverage Graph

A http tool for reverse proxy like nginx (NO Framework, just write in PURE Go)

Use

  • Install Golang
$ brew install golang
  • Build app
$ make build
  • Copy config.example.json to config.json
$ cp config.example.json config.json
  • Add your services in config.json
{
    "services": [
        {
            "root": "[root for service, example: /myapp]",
            "host": "[host service, example: http://localhost:8000]"
        }
    ]
}
  • Set app port
{
    "gateway_port": 3000,
}
  • Run binary
$ ./bin
[GATEWAY] :3000/myapp/ |===> http://localhost:8000
Server running on port :3000

In nginx, configuration for adding proxy like this:

location /myapp/ {
    proxy_pass http://127.0.0.1:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect    off;
}

In this app, for adding a proxy just add in config.json