Sha256: d49baae0ef0f7447a86414ea7d0ce56c55d0ac99941832f0994755e15c410252

Contents?: true

Size: 589 Bytes

Versions: 1

Compression:

Stored size: 589 Bytes

Contents

require "fluent_logger_statistics/app"

module FluentLoggerStatistics
  class Middleware
    def initialize(app, endpoint, loggers)
      @app = app
      @fluent_apps = loggers.map{|resource, logger|
        path = [ endpoint.chomp('/'), resource ].join('/')
        [ path, App.new(logger) ]
      }.to_h
    end

    ACCEPT_METHODS = ['GET'].freeze

    def call(env)
      path = env['PATH_INFO'].chomp('/')
      if @fluent_apps[path] && ACCEPT_METHODS.include?(env['REQUEST_METHOD'])
        @fluent_apps[path].call(env)
      else
        @app.call(env)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent_logger_statistics-0.2.0 lib/fluent_logger_statistics/middleware.rb