Sha256: 400b9e12af3f51928ca8b764777e3a41c0c7608f02ce69923b811666c74afc05

Contents?: true

Size: 530 Bytes

Versions: 2

Compression:

Stored size: 530 Bytes

Contents

# frozen_string_literal: true

module ApiProxy
  class Middleware
    def initialize(app, namespace = :default)
      @app = app
      @config = ApiProxy.configuration(namespace)
    end

    def call(env)
      return @app.call(env) unless env['REQUEST_PATH'].start_with?(@config.request_starts_with)

      builder = RequestOptionsBuilder.new(env, @config)
      request = ApiProxy::Request.new(builder)

      response = request.result

      Rack::Response.new(response.to_s, response.code, request.headers)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
api_proxy-0.1.1 lib/api_proxy/middleware.rb
api_proxy-0.1.0 lib/api_proxy/middleware.rb