# Path-Based Routing
#
# Routes by URL path prefix. Longest prefix wins.
#   /api/*    -> api cluster
#   /static/* -> static cluster
#   /*        -> default cluster
#
# Also demonstrates:
#   - Exact path matching via conditions (path: "/healthz")
#   - Method-based filtering via conditions (methods: [GET, HEAD])
#
# The router itself uses path_prefix for matching. Exact path
# and method constraints are applied via the condition system on
# individual filters.
#
# Usage:
#   cargo run -p praxis-proxy -- -c examples/configs/traffic-management/path-based-routing.yaml
#   curl http://localhost:8080/api/users
#   curl http://localhost:8080/static/index.html
#   curl http://localhost:8080/healthz
#   curl http://localhost:8080/

listeners:
  - name: default
    address: "127.0.0.1:8080"
    filter_chains:
      - main

filter_chains:
  - name: main
    filters:
      - filter: router
        routes:
          - path_prefix: "/api/"
            cluster: api

          - path_prefix: "/static/"
            cluster: static

          - path_prefix: "/"
            cluster: default

      # Exact path match: only /healthz (not /healthz/deep).
      - filter: headers
        response_set:
          - name: "X-Health-Check"
            value: "ok"
        conditions:
          - when:
              path: "/healthz"

      # Method constraint: add cache headers for read-only requests.
      - filter: headers
        response_set:
          - name: "Cache-Control"
            value: "public, max-age=300"
        conditions:
          - when:
              path_prefix: "/static/"
              methods: [GET, HEAD]

      - filter: load_balancer
        clusters:
          - name: api
            endpoints:
              - "127.0.0.1:3001"
              - "127.0.0.1:3002"
              - "127.0.0.1:3003"

          - name: static
            endpoints:
              - "127.0.0.1:4000"

          - name: default
            endpoints:
              - "127.0.0.1:5000"

insecure_options:
  allow_private_endpoints: true # example proxies to local backends
