1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! API gateway / reverse proxy
//!
//! Routes path prefixes to groups of upstream servers: round-robin balancing,
//! retries of idempotent requests on another upstream, passive health checks
//! (an upstream that keeps failing is skipped for a while, then probed again),
//! timeouts (504) and connection errors (502), streamed responses, forwarded
//! headers, per-client rate limiting, request ids, JSON access log and
//! Prometheus metrics for the operator.
//!
//! Configuration (environment):
//! PORT listen port (default 8080)
//! GATEWAY_ROUTES `prefix=upstream[,upstream...];prefix=...`, e.g.
//! `/api/users=http://10.0.0.5:9000,http://10.0.0.6:9000;/api/orders=http://10.0.0.7:9000`
//! GATEWAY_ADMIN_KEY key for /_gateway/status and /_gateway/metrics (required unless DEV=1)
//! DEV 1 = demo route /echo -> http://127.0.0.1:9001 and key "dev-admin-key"
//!
//! Run: DEV=1 cargo run --example gateway (then start something on :9001)
//! Try: curl -i localhost:8080/echo/hello
//! curl -H 'x-api-key: dev-admin-key-dev-admin-key' localhost:8080/_gateway/status
async