Sha256: 16ffd6523ca1cf9c996987130194c066ef4150b0f3859d2902a26d35713d3013

Contents?: true

Size: 848 Bytes

Versions: 20

Compression:

Stored size: 848 Bytes

Contents

module Rodauth
  module Rails
    # Middleware that's added to the Rails middleware stack. Normally the main
    # Roda app could be used directly, but this trick allows the app class to
    # be reloadable.
    class Middleware
      def initialize(app)
        @app = app
      end

      def call(env)
        return @app.call(env) if asset_request?(env)

        app = Rodauth::Rails.app.new(@app)

        # allow the Rails app to call Rodauth methods that throw :halt
        catch(:halt) do
          app.call(env)
        end
      end

      # Check whether it's a request to an asset managed by Sprockets or Propshaft.
      def asset_request?(env)
        return false unless ::Rails.application.config.respond_to?(:assets)

        env["PATH_INFO"] =~ %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rodauth-rails-1.12.0 lib/rodauth/rails/middleware.rb
rodauth-rails-1.11.0 lib/rodauth/rails/middleware.rb
rodauth-rails-1.10.0 lib/rodauth/rails/middleware.rb
rodauth-rails-1.9.0 lib/rodauth/rails/middleware.rb
rodauth-rails-1.8.0 lib/rodauth/rails/middleware.rb
rodauth-rails-1.7.1 lib/rodauth/rails/middleware.rb
rodauth-rails-1.7.0 lib/rodauth/rails/middleware.rb
rodauth-rails-1.6.4 lib/rodauth/rails/middleware.rb
rodauth-rails-1.6.3 lib/rodauth/rails/middleware.rb
rodauth-rails-1.6.2 lib/rodauth/rails/middleware.rb
rodauth-rails-1.6.1 lib/rodauth/rails/middleware.rb
rodauth-rails-1.6.0 lib/rodauth/rails/middleware.rb
rodauth-rails-1.5.5 lib/rodauth/rails/middleware.rb
rodauth-rails-1.5.4 lib/rodauth/rails/middleware.rb
rodauth-rails-1.5.2 lib/rodauth/rails/middleware.rb
rodauth-rails-1.5.1 lib/rodauth/rails/middleware.rb
rodauth-rails-1.5.0 lib/rodauth/rails/middleware.rb
rodauth-rails-1.4.2 lib/rodauth/rails/middleware.rb
rodauth-rails-1.4.1 lib/rodauth/rails/middleware.rb
rodauth-rails-1.4.0 lib/rodauth/rails/middleware.rb