# Cross-Chain Flat Pipeline
#
# A listener references two chains: preprocessing and
# routing. Both are concatenated into one flat pipeline,
# so a branch in preprocessing can rejoin at a named
# filter in routing using just the filter name.
#
# Use case: separation of concerns where a preprocessing
# classifier detects a fast-path condition and skips the
# rest of preprocessing to go straight to routing.
#
# NOTE: The on_result condition here is a template. The
# headers filter does not produce filter results. When a
# result-producing filter (e.g. a classifier) is added,
# it would write results that trigger this branch.
#
# Usage:
#   cargo run -p praxis-proxy -- -c examples/configs/branching/cross-chain-flat.yaml

listeners:
  - name: web
    address: "127.0.0.1:8080"
    # Two chains concatenated into one flat pipeline
    filter_chains: [preprocessing, routing]

filter_chains:
  - name: preprocessing
    filters:
      # Security filters run before the branch host: a skip-to rejoin
      # may never bypass one
      - filter: cors
        allow_origins:
          - "*"

      # Classifier: detects fast-path eligibility
      - filter: headers
        request_add:
          - name: X-Preprocess
            value: "true"
        branch_chains:
          # Fast-path requests skip the remaining
          # preprocessing (request_id) and jump
          # directly to the routing chain
          - name: shortcut_to_route
            # Fires when classifier reports a fast-path
            # condition (template: no filter currently
            # writes this result)
            on_result:
              filter: headers
              key: status
              result: fast_path
            # Target is in the routing chain; works
            # because both chains are flattened
            rejoin: route
            chains:
              - name: fast_path_prep
                filters:
                  # Tag fast-path for observability
                  - filter: headers
                    request_add:
                      - name: X-Fast-Path
                        value: "true"

      # Remaining preprocessing: skipped on fast-path
      - filter: request_id

  - name: routing
    filters:
      # Named target for cross-chain skip-to rejoin
      - filter: router
        name: route
        routes:
          - path_prefix: "/"
            cluster: backend

      - filter: load_balancer
        clusters:
          - name: backend
            endpoints:
              - "127.0.0.1:3000"

insecure_options:
  allow_private_endpoints: true # example proxies to local backends
