dgate 2.1.0

DGate API Gateway - High-performance API gateway with JavaScript module support
Documentation
# DGate v2 Configuration
# Compatible with https://dgate.io/docs/getting-started/dgate-server

version: v1
log_level: ${LOG_LEVEL:-info}
log_json: false
debug: true
tags: ["test", "dgate-v2"]

# Storage configuration
storage:
  type: file
  dir: .dgate/data/

# Proxy server configuration  
proxy:
  port: ${PORT:-80}
  host: 0.0.0.0
  console_log_level: info
  
  # Global headers added to all responses
  global_headers:
    X-Powered-By: DGate-v2
  
  # HTTP client transport settings
  client_transport:
    disable_private_ips: false
  
  # Initial resources loaded at startup
  init_resources:
    namespaces:
      - name: "default"
        tags: ["default"]
      - name: "url_shortener"
        tags: ["example"]
    
    services:
      - name: "httpbin"
        namespace: "default"
        urls: 
          - "https://httpbin.org"
        request_timeout_ms: 30000
    
    collections:
      - name: "short_links"
        namespace: "url_shortener"
        visibility: private
    
    modules:
      # Health check - using inline raw JavaScript (payloadRaw)
      - name: "health-check"
        namespace: "default"
        moduleType: javascript
        payloadRaw: |
          function requestHandler(ctx) {
            ctx.json({ 
              status: 'healthy', 
              timestamp: new Date().toISOString(),
              version: 'v0.1.0'
            });
          }
      
      # Echo handler - using inline raw JavaScript (payloadRaw)
      - name: "echo-handler"
        namespace: "default"
        moduleType: javascript
        payloadRaw: |
          function requestHandler(ctx) {
            ctx.json({
              method: ctx.request.method,
              path: ctx.request.path,
              query: ctx.request.query,
              headers: ctx.request.headers,
              body: ctx.request.body,
              params: ctx.params
            });
          }
      
      # URL Shortener - using file reference (payloadFile)
      - name: "url-shortener"
        namespace: "url_shortener"
        moduleType: javascript
        payloadFile: "module_examples/url_shortener.js"
    
    routes:
      # Default namespace routes
      - name: "httpbin-route"
        namespace: "default"
        paths: ["/httpbin/**"]
        methods: ["*"]
        service: "httpbin"
        strip_path: true
      
      - name: "echo-route"
        namespace: "default"
        paths: ["/echo"]
        methods: ["GET", "POST"]
        modules: ["echo-handler"]
      
      - name: "health-route"
        namespace: "default"
        paths: ["/health"]
        methods: ["GET"]
        modules: ["health-check"]
      
      # URL Shortener routes
      - name: "url-shortener-create"
        namespace: "url_shortener"
        paths: ["/"]
        methods: ["GET", "POST"]
        modules: ["url-shortener"]
      
      - name: "url-shortener-redirect"
        namespace: "url_shortener"
        paths: ["/{id}"]
        methods: ["GET"]
        modules: ["url-shortener"]
    
    domains:
      # Route url_shortener.localhost to the url_shortener namespace
      - name: "url-shortener-domain"
        namespace: "url_shortener"
        patterns: ["url_shortener.*", "short.*"]

# Admin API configuration
admin:
  port: 9080
  host: 0.0.0.0
  allow_list:
    - "127.0.0.1/8"
    - "::1"

# Cluster configuration (Raft consensus)
# Uncomment to enable cluster mode for high availability
#
# cluster:
#   enabled: true
#   
#   # Unique node ID (must be different for each node in the cluster)
#   node_id: 1
#   
#   # Address this node advertises to other nodes
#   advertise_addr: "192.168.1.10:9090"
#   
#   # Port for Raft inter-node communication
#   raft_port: 9090
#   
#   # Bootstrap as single-node cluster (use for first node only)
#   bootstrap: true
#   
#   # Static list of initial cluster members (alternative to discovery)
#   # initial_members:
#   #   - id: 1
#   #     addr: "192.168.1.10:9090"
#   #   - id: 2
#   #     addr: "192.168.1.11:9090"
#   #   - id: 3
#   #     addr: "192.168.1.12:9090"
#   
#   # DNS-based discovery (useful for Kubernetes headless services)
#   # discovery:
#   #   type: dns
#   #   dns_name: "dgate-headless.default.svc.cluster.local"
#   #   dns_port: 9090
#   #   refresh_interval_secs: 30
#   
#   # Raft tuning parameters
#   heartbeat_interval_ms: 500
#   election_timeout_min_ms: 1500
#   election_timeout_max_ms: 3000
#   snapshot_threshold: 1000