0

I have the thin server running (without any web application framework). In the routing pattern, the order of matching patterns does not seem to make difference. Whether I do:

Rack::Handler::Thin.run(Rack::Builder.new do
  map("/"){...}
  map("/foo/"){...}
end, Port: 3000)

or

Rack::Handler::Thin.run(Rack::Builder.new do
  map("/foo/"){...}
  map("/"){...}
end, Port: 3000)

the request to localhost:3000/foo/ will be correctly picked up by map("/foo/"){...} and not by map("/"){...}. How it this priority determined?

For some web application frameworks, for example in Sinatra, it says Routes are matched in the order they are defined. The first route that matches the request is invoked, which is not the case with the setup I have with my app.

sawa
  • 165,429
  • 45
  • 277
  • 381

1 Answers1

1

https://github.com/rack/rack/blob/master/lib/rack/urlmap.rb

Priority doesn't determined in Rack::URLMap. It matched by full path of the resource, that you provide with

map(){ ... }
crackedmind
  • 918
  • 6
  • 14
  • 1
    Your answer does not answer my question, but the page you linked has a description saying `URLMap dispatches in such a way that the longest paths are tried first, since they are most specific`, which answers my question. And lines 38--40 have the relevant code `sort_by do |(host, location, _, _)| [host ? -host.size : INFINITY, -location.size] end`. – sawa Jul 31 '13 at 09:04