SecNex

Configuration

Configuration of API Gateway

The gateway is configured via a single YAML file (gateway.yaml). This document describes all available configuration options.

Configuration File Structure

gateway:
  host: "0.0.0.0"
  port: 8080
  features:
    - request_id
    - real_ip
    - logger

proxies:
  - id: "proxy-id"
    host: "example.com"
    target: "http://backend:3000"

apis:
  - id: "api-id"
    target: "https://api.example.com"

routes:
  - id: "route-id"
    path: "/api/v1/*"
    strip_prefix:
      enabled: true
      prefix: "/api/v1"
    security:
      auth:
        enabled: true
        type: "api_key"
        header: "X-Api-Key"
        path:
          include: []
          exclude: []
      waf:
        enabled: true
        methods: ["GET", "POST"]

Sections

Gateway

Global gateway configuration.

FieldTypeDescriptionDefault
hoststringHost address to bind toRequired
portintegerPort numberRequired
featuresarrayGlobal middleware featuresRequired

Features

Available global features:

FeatureDescription
request_idAdds unique request ID to each request
real_ipDetermines real client IP from headers
loggerLogs all HTTP requests

Proxies

Virtual hosting configuration for host-based routing.

FieldTypeDescription
idstringUnique proxy identifier
hoststringDomain/host name to match
targetstringBackend URL to proxy to

APIs

Backend service definitions referenced by routes.

FieldTypeDescription
idstringUnique API identifier (referenced by routes)
targetstringBackend URL

Routes

Route definitions with security policies.

FieldTypeDescription
idstringUnique route identifier (must match API ID)
pathstringChi route pattern (e.g., /api/v1/*)
strip_prefixobjectPrefix stripping configuration
securityobjectSecurity policies (auth, WAF)

Strip Prefix

FieldTypeDescription
enabledbooleanEnable prefix stripping
prefixstringPrefix to remove from path

Security

Authentication
FieldTypeDescription
enabledbooleanEnable authentication
typestringAuth type (api_key, session, etc.)
headerstringHeader name to validate
pathobjectPath-based filtering
Auth Path Filtering
FieldTypeDescription
includearrayPaths that require auth (empty = all)
excludearrayPaths that skip auth

Include/Exclude Logic:

  • If include is set → only matching paths require auth
  • If include is empty → all paths require auth except exclude

Wildcards (*) are supported in path patterns.

WAF (Web Application Firewall)
FieldTypeDescription
enabledbooleanEnable WAF
methodsarrayAllowed HTTP methods (["*"] for all)

Example Configurations

Public API (No Auth)

routes:
  - id: "public-api"
    path: "/public/*"
    strip_prefix:
      enabled: true
      prefix: "/public"
    security:
      auth:
        enabled: false
      waf:
        enabled: true
        methods: ["GET", "POST"]

Protected API with API Key

routes:
  - id: "protected-api"
    path: "/api/v1/*"
    strip_prefix:
      enabled: true
      prefix: "/api/v1"
    security:
      auth:
        enabled: true
        type: "api_key"
        header: "X-Api-Key"
      waf:
        enabled: true
        methods: ["*"]

Mixed Auth (Path-based)

routes:
  - id: "mixed-api"
    path: "/api/*"
    security:
      auth:
        enabled: true
        header: "Authorization"
        path:
          include: ["/api/admin/*", "/api/users/*/profile"]
          exclude: ["/api/health", "/api/public/*"]
      waf:
        enabled: true
        methods: ["*"]

Configuration Loading

The gateway loads configuration from a file path relative to the binary:

cfg, err := config.NewFileConfig("../gateway.yaml")

For Docker deployments, mount the config file:

volumes:
  - ./gateway.yaml:/app/gateway.yaml:ro