Dan Webb's Request Routing Plugin
Posted by josh May 22, 2006 @ 03:06 AM
Have you ever wanted to write Rails routes using a URL's subdomain? What about routing based on whether a request was HTTP vs HTTPS? Well, now you can. Recently Dan Webb released his "Request Routing Plugin":http://svn.vivabit.net/external/rubylibs/requestrouting/README for public use. This plugin lets you create routing rules that use a whole slew of new properties: domain, subdomain, method, port, remoteip, contenttype, accepts, requesturi, and protocol.
You can obtain the plugin from Dan's subversion repository:
ruby script/plugin install \
http://svn.vivabit.net/external/rubylibs/request_routing/

Dan, this is really cool. How is the performance? I imagine that setting the routes in LightTPD directly is faster, but I wonder by how much. If this is fairly comperable (say within 5-8%) then it would be worth the ease of use (and I can always reclaim that if I need it).
thanks again dan for writting this. Excellent.
this is great. This is exactly what i was looking for about a month ago for an internal application that has its mini apps segmented by subdomain. Excellent.
Awesome mate!
Adam: Performance-wise I don’t think there’s going to be much impact. The plugin works by generating a single conditional statement for each route although I’ve not benchmarked it as yet.
A few more usage examples (subdomains, method, protocol) would be super useful. Also information on how to test on a local machine with this plugin / subdomains would be helpful as well.
Please!!! :)
I agree, benchmark it and provide some additional information. Also, the ability to use more than one subdomain would be appreciated.
Hey Dan, I was actually curious about the speed difference using your plug-in in combination with the routing framework to do some of these redirects rather than using .htaccess directly. But as you stated, since it is just a conditional check, it won’t really be slower than comparing routing to .htaccess, which we already know.
So thank you again for the plugin and appreciate the response.
A quick patch to make it work with Duane hack
Change"@request.#{ (key == :subdomain) ? "subdomains.first" : key.to_s } =~ #{value.inspect}"to"#{value.inspect} =~ @request.#{ (key == :subdomain) ? "subdomains.first" : key.to_s }"