Class: BetterAuth::Roda::MountedApp

Inherits:
Object
  • Object
show all
Defined in:
lib/better_auth/roda/mounted_app.rb

Instance Method Summary collapse

Constructor Details

#initialize(auth, mount_path:) ⇒ MountedApp

Returns a new instance of MountedApp.



8
9
10
11
# File 'lib/better_auth/roda/mounted_app.rb', line 8

def initialize(auth, mount_path:)
  @auth = auth
  @mount_path = normalize_path(mount_path)
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/better_auth/roda/mounted_app.rb', line 24

def call(env)
  @auth.call(next_env(env))
rescue BetterAuth::APIError, JSON::ParserError
  raise
rescue => error
  handle_unexpected_error(error, env)
end

#mount_matches?(env) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
# File 'lib/better_auth/roda/mounted_app.rb', line 13

def mount_matches?(env)
  return false if @mount_path == "/"

  path_info = normalize_path(env["PATH_INFO"], trim: true)
  return true if path_info == @mount_path || path_info.start_with?("#{@mount_path}/")
  return true if script_mount_matches?(normalize_path(env["SCRIPT_NAME"], trim: true))

  full = full_request_path(env)
  full == @mount_path || full.start_with?("#{@mount_path}/")
end