Module: AnyCable::Rails::Rack
- Defined in:
- lib/anycable/rails/rack.rb
Overview
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 middleware by default to its own stack.
You can also use any Rack/Rails middleware you want. For example, to enable CustomMiddleware you can add the following code to an initializer or any other configuration file:
AnyCable::Rails::Rack.middleware.use CustomMiddleware
Class Method Summary collapse
Class Method Details
.app ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/anycable/rails/rack.rb', line 43 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 |
.app_build_lock ⇒ Object
25 26 27 |
# File 'lib/anycable/rails/rack.rb', line 25 def self.app_build_lock @app_build_lock end |
.default_middleware_stack ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/anycable/rails/rack.rb', line 35 def self.default_middleware_stack config = ::Rails.application.config ActionDispatch::MiddlewareStack.new do |middleware| middleware.use(config.session_store, config.) if config.session_store end end |
.middleware ⇒ Object
31 32 33 |
# File 'lib/anycable/rails/rack.rb', line 31 def self.middleware @middleware ||= ::Rails::Configuration::MiddlewareStackProxy.new end |