Sha256: efc8ec1c9d0840b71d9784ac2f63ce1c5dd050d057fb4c5722ee6041643c35d6

Contents?: true

Size: 959 Bytes

Versions: 1

Compression:

Stored size: 959 Bytes

Contents

# connects_to database:
module Gorynich
  module Head
    class RackMiddleware
      def initialize(app)
        @app = app
      end

      def call(env)
        tenant, opts = Gorynich.switcher.analyze(env)

        Gorynich.with(tenant, **opts) do
          if Rails.logger.respond_to?(:tagged)
            Rails.logger.tagged("Tenant(#{tenant})") { @app.call(env) }
          else
            @app.call(env)
          end
        end
      rescue Gorynich::UriNotFound => e
        Rails.logger.error(e.inspect)
        [404, { 'Content-Type' => 'text/plain', 'charset' => 'UTF-8' }, [e.message]]
      rescue Gorynich::HostNotFound => e
        Rails.logger.error(e.inspect)
        [404, { 'Content-Type' => 'text/plain', 'charset' => 'UTF-8' }, [e.message]]
      rescue Gorynich::TenantNotFound => e
        Rails.logger.error(e.inspect)
        [404, { 'Content-Type' => 'text/plain', 'charset' => 'UTF-8' }, [e.message]]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gorynich-1.3.0.213297 lib/gorynich/head/rack_middleware.rb