Question

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.

Was it helpful?

Solution

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(){ ... }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top