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/

Posted in Releases, Tools | 8 comments

Comments

  1. Adam on 22 May 17:12:

    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.

  2. Jon Maddox on 22 May 21:28:

    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.

  3. Dave Rosen on 23 May 04:30:

    Awesome mate!

  4. Dan Webb on 23 May 06:36:

    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.

  5. Britt on 23 May 21:14:

    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!!! :)

  6. Branstrom on 25 May 00:50:

    I agree, benchmark it and provide some additional information. Also, the ability to use more than one subdomain would be appreciated.

  7. Adam on 25 May 14:18:

    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.

  8. Iktorn on 30 May 08:42:

    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 }"