Sha256: da8e462e4aa28db8645568f0fceb4656ff15a22cf63e49311cd436ca0ce2d969

Contents?: true

Size: 1.76 KB

Versions: 36

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require "rails/configuration"
require "action_dispatch/middleware/stack"

module AnyCable
  module Rails
    # Rack middleware stack to modify the HTTP request object.
    #
    # AnyCable Websocket server does not use Rack middleware processing mechanism (which Rails uses
    # when Action Cable is mounted into the main app).
    #
    # Some middlewares could enhance request env with useful information.
    #
    # For instance, consider the Rails session middleware: it's responsible for restoring the
    # session data from cookies.
    #
    # AnyCable adds session middelware by default to its own stack.
    #
    # You can also use any Rack/Rails middleware you want. For example, to enable Devise/Warden
    # you can add the following code to an initializer or any other configuration file:
    #
    #   AnyCable::Rails::Rack.middleware.use Warden::Manager do |config|
    #     Devise.warden_config = config
    #   end
    module Rack
      def self.app_build_lock
        @app_build_lock
      end

      @app_build_lock = Mutex.new

      def self.middleware
        @middleware ||= ::Rails::Configuration::MiddlewareStackProxy.new
      end

      def self.default_middleware_stack
        config = ::Rails.application.config

        ActionDispatch::MiddlewareStack.new do |middleware|
          middleware.use(config.session_store, config.session_options) if config.session_store
        end
      end

      def self.app
        @rack_app || app_build_lock.synchronize do
          @rack_app ||= default_middleware_stack.yield_self do |stack|
                          middleware.merge_into(stack)
                        end.yield_self do |stack|
            stack.build { [-1, {}, []] }
          end
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
anycable-rails-core-1.5.1 lib/anycable/rails/rack.rb
anycable-rails-core-1.5.0 lib/anycable/rails/rack.rb
anycable-rails-core-1.5.0.rc.1 lib/anycable/rails/rack.rb
anycable-rails-core-1.4.4 lib/anycable/rails/rack.rb
anycable-rails-core-1.4.3 lib/anycable/rails/rack.rb
anycable-rails-core-1.4.2 lib/anycable/rails/rack.rb
anycable-rails-core-1.4.1 lib/anycable/rails/rack.rb
anycable-rails-core-1.4.0 lib/anycable/rails/rack.rb
anycable-rails-1.4.0 lib/anycable/rails/rack.rb
anycable-rails-1.4.0.rc.4 lib/anycable/rails/rack.rb
anycable-rails-1.4.0.rc.3 lib/anycable/rails/rack.rb
anycable-rails-1.4.0.rc.2 lib/anycable/rails/rack.rb
anycable-rails-1.4.0.rc.1 lib/anycable/rails/rack.rb
anycable-rails-1.3.7 lib/anycable/rails/rack.rb
anycable-rails-1.3.6 lib/anycable/rails/rack.rb
anycable-rails-1.3.5 lib/anycable/rails/rack.rb
anycable-rails-1.3.4 lib/anycable/rails/rack.rb
anycable-rails-1.3.3 lib/anycable/rails/rack.rb
anycable-rails-1.3.2 lib/anycable/rails/rack.rb
anycable-rails-1.3.1 lib/anycable/rails/rack.rb