Method: Jets::Server::RouteMatcher#proxy_detection

Defined in:
lib/jets/server/route_matcher.rb

#proxy_detection(route_path, actual_path) ⇒ Object

catchall/globbing/wildcard/proxy routes. Examples:

get "files/*path", to: "files#show"
get "others/*rest", to: "others#show"
get "*catchall", to: "public_files#show" # last catchall route for Jets


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jets/server/route_matcher.rb', line 54

def proxy_detection(route_path, actual_path)
  # drop the proxy_segment
  leading_path = route_path.split('/')[0..-2].join('/')

  # get "*catchall", to: "public_files#show"
  if leading_path.empty? # This is the last catchall route "*catchall"
    return true # always return true here because the entire path
    # will always match
  end

  # Other types of wildcard route:
  #
  #    get "files/*path", to: "files#show"
  #    get "others/*rest", to: "others#show"
  unless leading_path.ends_with?('/')
    # Ensure trailing slash to make pattern matching stricter
    leading_path = "#{leading_path}/"
  end

  pattern = "^#{leading_path}"
  regexp = Regexp.new(pattern)
  !!regexp.match(actual_path) # could be true or false
end