Skip to content

GatewayConfig

Thiago Bustamante edited this page Jun 12, 2018 · 30 revisions

This is the Gateway config descriptor. It support the following properties:

Property Type Description Required
protocol ProtocolConfig The gateway protocol configuration. true
underProxy boolean If we are behind a reverse proxy (Heroku, Bluemix, AWS if you use an ELB, custom Nginx setup, etc). false
disableCompression boolean By default, all responses are compressed by the gateway. If you want to disable it set this property to true. false
disableApiIdValidation boolean Disable the validation of API Ids. If the id is not validated, the data could not be synchronizable to Leanty dashboard. false
logger LoggerConfig Configurations for gateway logger. false
accessLogger AccessLoggerConfig Configurations for gateway access logger. false
admin AdminConfig If provided, Configure the admin service for the gateway. false
cors CorsConfig Configure default cors support for API requests. It can be configured also in the API configuration. false
timeout string or number Configure a timeout for the gateway http.Server. You can inform the amount of milisencods, or use a human-interval string. Defaults to 'one minute'. false
filter MiddlewareConfig[] An array of installed Filter middlewares to be executed, in order, by the request pipeline. false
serviceDiscovery ServiceDiscoveryConfig[] Configure Service Discovery Providers. false
healthcheck string Configure an healthcheck endpoint for the gateway. Provide here the path where the healthcheck service will respond. false
errorHandler MiddlewareConfig[] An ErrorHandler middleware to be called to handle any error during any request pipeline processing. false
config ApiPipelineConfig Declare common configurations to be referenced by differente apis. false
analytics RequestAnalyticsConfig Inform how request analytics should be stored by the gateway. false

Example:

{
    "gateway": {
        "protocol": {
            "http": {
                "listenPort": 8000
            }
        },
        "admin": {
            "protocol": {
                "http": {
                    "listenPort": 8001
                }
            },
            "accessLogger": {
                "msg": "HTTP {{req.method}} - {{res.statusCode}} - {{req.url}} ({{res.responseTime}}ms) ",
                "console": {
                    "timestamp": true,
                    "colorize": true
                }
            },
            "userService": {
                "jwtSecret": "secret"
            }
        },
        "logger": {
            "level": "info",
            "console": {
                "colorize": true
            },
            "file": {
                "timestamp": true,
                "outputDir": "./logs",
                "json": false, 
                "prettyPrint": true 
            }
        },
        "monitor": [
            {
                "name": "cpu",
                "statsConfig": {
                    "granularity": {
                        "duration": "1 minute",
                        "ttl": "2 days"
                    }
                }            
            }
        ],
        "filter": [{
            "name": "ipFilter",
            "options": {
                "blacklist": ["10.100.*.*"]
            }
        }]        
    }
} 

or

gateway:
  protocol:
    http:
      listenPort: 8000
  admin:
    protocol:
      http:
        listenPort: 8001
    accessLogger:
      msg: 'HTTP {{req.method}} - {{res.statusCode}} - {{req.url}} ({{res.responseTime}}ms)'
      console:
        timestamp: true
        colorize: true
    userService:
      jwtSecret: secret
  logger:
    level: info
    console:
      colorize: true
    file:
      timestamp: true
      outputDir: "./logs"
      json: false
      prettyPrint: true
  monitor:
  - name: cpu
    statsConfig:
      granularity:
        duration: 1 minute
        ttl: 2 days
  filter:
    - name: ipFilter 
      options: 
        blacklist: 
          - "10.100.*.*"
  analytics:
    enabled: true
    logger: redis

ApiPipelineConfig

Declare common configurations that can be used by different APIs.

The config configuration supports the following properties:

Property Type Description Required
authentication { [index: string]: AuthenticationConfig } Authentication configuration. false
cache { [index: string]: CacheConfig } Cache configuration. false
circuitBreaker { [index: string]: CircuitBreakerConfig } CircuitBreaker configuration. false
cors { [index: string]: CorsConfig } Cors configuration. false
filter { [index: string]: MiddlewareConfig } Filter configuration. false
throttling { [index: string]: ThrottlingConfig } Throttling configuration. false
interceptor Interceptors Interceptors configuration. false
errorHandler { [index: string]: MiddlewareConfig } ErrorHandler configuration. false

Example:

gateway:
    config:
        authentication:
            my-basic-validator:
                strategy:
                    id: basic
                    options:
                        verify:
                            name: verifyBasicUser
        cache:
            my-cache:
                client:
                    cacheTime: 1 minute
                    cacheControl: public
                    mustRevalidate: false
                    noTransform: false
                    proxyRevalidate: false
                server:
                    cacheTime: 10 minutes
                    binary: true
                    preserveHeaders: access-control-allow-credentials
        circuitBreaker:
            my-circuit-breaker:
                timeout: 1
                resetTimeout: 3 seconds
                timeWindow: 2 seconds
                maxFailures: 1
                onOpen:
                    name: myOpenHandler
        throttling:
            my-rate-limit:
                timeWindow: one minute
                delay: 1 second
                max: 1
        cors:
            my-cors:
                origin:
                    enableAll: true
        filter:
            my-ip-filter:
                name: ipFilter
                options:
                    blacklist:
                        - "127.0.0.1"
                        - "::1"
                    statusCode: 403
                    message: IP Filtered
        interceptor:
            request:
                my-interceptor:
                    name: myRequestInterceptor
                    options:
                        parameter1: value1
            response:
                my-other- interceptor:
                    name: myResponseInterceptor
                    

RequestAnalyticsConfig

Inform how request analytics should be stored by the gateway. Supports the following properties:

Property Type Description Required
enabled boolean Enable log recording for the gateway requests. false
logger MiddlewareConfig The logger middleware. false

Example:

gateway:
    analytics:
        enabled: true
        logger:
            name: redis
            options:
                maxEntries: 2000

You can use any custom middleware to handle the gateway log requests. Tree Gateway already includes a middleware to store the logs into the redis.

This example configure the gateway to use the redis middleware. It will keep the last 2000 entries under a list called {REQUEST_LOG}

Clone this wiki locally