Module: Lennarb::Plugins::Mount::InstanceMethods

Defined in:
lib/lennarb/plugins/mount.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lennarb/plugins/mount.rb', line 34

def call(env)
  path_info = env[Rack::PATH_INFO]

  self.class.instance_variable_get(:@_mounted_apps)&.each do |mount_path, app|
    next unless path_info.start_with?("#{mount_path}/") || path_info == mount_path

    env[Rack::PATH_INFO]   = path_info[mount_path.length..]
    env[Rack::PATH_INFO]   = '/' if env[Rack::PATH_INFO].empty?
    env[Rack::SCRIPT_NAME] = "#{env[Rack::SCRIPT_NAME]}#{mount_path}"

    return app.call(env)
  end

  super
rescue StandardError => e
  handle_error(e)
end