Sha256: a03b33e49902e5800eae6ae70c32b48adabe6f85d134a1e45de37d071fed16e2

Contents?: true

Size: 1 KB

Versions: 12

Compression:

Stored size: 1 KB

Contents

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

      def call(env)
        @config ||= Gorynich.instance
        @config.actualize

        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

12 entries across 12 versions & 1 rubygems

Version Path
gorynich-1.2.3.198656 lib/gorynich/head/rack_middleware.rb
gorynich-1.2.2.198643 lib/gorynich/head/rack_middleware.rb
gorynich-1.2.1.184916 lib/gorynich/head/rack_middleware.rb
gorynich-1.2.0.180668 lib/gorynich/head/rack_middleware.rb
gorynich-1.1.1.148381 lib/gorynich/head/rack_middleware.rb
gorynich-1.1.0.142168 lib/gorynich/head/rack_middleware.rb
gorynich-1.1.0.142154 lib/gorynich/head/rack_middleware.rb
gorynich-1.1.0.142147 lib/gorynich/head/rack_middleware.rb
gorynich-1.1.0.142142 lib/gorynich/head/rack_middleware.rb
gorynich-1.1.0.142139 lib/gorynich/head/rack_middleware.rb
gorynich-1.1.0.142136 lib/gorynich/head/rack_middleware.rb
gorynich-1.1.0.142046 lib/gorynich/head/rack_middleware.rb