Sign inSign up

0lucho0/echo-back

By 0lucho0

โ€ขUpdated about 2 months ago

Image
0

1.2K

0lucho0/echo-back repository overview

โ Echo-Back

Lint & Test Docker Publish codecov Go Version Docker License Last Commit

A customizable default backend written in Go for use with the Ingress-NGINX controllerโ .
EchoBack provides friendly HTML and JSON error responses for unmatched routes or backend failures in your Kubernetes cluster.

โš ๏ธ This project is designed to be used as the default-backend in the Ingress-NGINX controller configuration.

โ โœจ Features

  • ๐Ÿงพ Dual-format response: HTML & JSON
  • ๐Ÿ” Rich metadata in response: request headers, client IP, method, URI
  • ๐Ÿงฉ Easy-to-customize HTML templates
  • ๐Ÿš€ Lightweight and high-performance Go binary
  • ๐Ÿ“Š Built-in metrics with Prometheus support

โ ๐Ÿ—๏ธ Architecture

flowchart TD
    client["Client"]
    nginx_proxy["Ingress-NGINX"]
    default_go["Default Backend (Go)"]
    service_python["Service (Python)"]

    client --> nginx_proxy
    nginx_proxy -->|HTTP Request| service_python
    service_python -->|HTTP Response| nginx_proxy
    nginx_proxy -- http-errors --> default_go
    default_go -->|HTTP Response| nginx_proxy
    nginx_proxy -->|HTTP Response| client

โ โš™๏ธ Environment Variables

VariableDescriptionDefault
PORTPort the server listens on3000
TEMPLATE_HTMLPath to HTML templatetemplates/simple.html
DEBUGEnables debug mode (logs body, etc.)true
LOG_LEVELLogging level (debug, info, ...)info
LOG_FORMATLogging format (text, json)text

โ ๐Ÿ“˜ API Reference

โ Endpoint: /

The root endpoint catches all unmatched requests and returns an HTML or JSON response based on request headers.

โ ๐Ÿ“ฅ Request Headers
Header NameDescriptionRequired
X-Request-IDUnique identifier for tracing the requestNo
X-Client-AddrIP address of the clientNo
X-CodeHTTP status code to return (defaults to 200)No
X-Service-NameName of the upstream serviceNo
X-Service-PortPort of the upstream serviceNo
X-Ingress-NameName of the Ingress resourceNo
X-NamespaceKubernetes namespace where the service residesNo
Content-TypeFormat of the request payload (e.g., application/json)No
AcceptAccepted response format (e.g., application/json)No

โ ๐Ÿ“ค Response

The response format is determined by the Accept or Content-Type headers.

โ ๐Ÿงพ JSON Response

Returned when Accept or Content-Type is application/json.

{
  "api": {
    "metadata": {
      "name": "echoback",
      "version": "v1.0.0",
      "commit": "abc123"
    },
    "spec": {
      "request": {
        "host": "example.com",
        "method": "GET",
        "uri": "/",
        "request_id": "12345",
        "client_addr": "192.168.1.1",
        "scheme": "https",
        "headers": {
          "User-Agent": "...",
          "X-Code": "404"
        },
        "body": {}
      },
      "response": {
        "status": 404,
        "status_text": "Not Found",
        "status_emoji": "๐Ÿ˜•",
        "service_name": "my-service",
        "service_port": "80",
        "ingress_name": "my-ingress",
        "namespace": "default"
      }
    }
  }
}
โ ๐Ÿ–ผ๏ธ HTML Response

Returned when Accept or Content-Type is text/html (or not specified). A template-based HTML error page will be rendered.

โ ๐Ÿ“ฆ Example Requests
โ JSON Request
GET / HTTP/1.1
Host: localhost
X-Request-ID: 12345
X-Client-Addr: 192.168.1.1
Content-Type: application/json
Accept: application/json
โ HTML Request
GET / HTTP/1.1
Host: localhost
X-Request-ID: 12345
X-Client-Addr: 192.168.1.1
Content-Type: text/html
Accept: text/html

โ ๐Ÿš€ Deployment (Helm Chart)

To use EchoBack as your Ingress-NGINX default backend, configure your values like this:

controller:
  defaultBackend:
    enabled: true
    image:
      repository: docker.io/0lucho0/echo-back
      tag: latest

Or deploy directly as a service in Kubernetes behind a catch-all ingress path.

โ ๐Ÿ› ๏ธ Build & Run Locally

make build
dist/echoback

Or run with Docker:

make docker-build
# or
docker compose up -d --build

โ ๐Ÿค Contributing

Pull requests and suggestions are welcome! Please open an issue first if you want to propose major changes.

โ ๐Ÿ“œ License

This project is licensed under the MIT License. See the LICENSEโ  file for more details.

Tag summary

Content type

Image

Digest

sha256:9e5775c6eโ€ฆ

Size

4.6 MB

Last updated

over 1 year ago

docker pull 0lucho0/echo-back