Monday, 5 September 2011

Rack::URLMap failing with Phusion Passenger

I'll make this quick, I've found that if I try and use Rack::URLMap with Phusion Passenger, it always results in a text/plain page that says 'Not Found: '. This will not do.

Something to do with the way Rack::URLMap matches against the map, it uses the env["SERVER_NAME"] which for some reason, Phusion passenger sets to "_", I've written a money patch that sets it to the same value as env["HTTP_HOST"] which solves the problem.

class Rack::URLMap
  alias_method :old_call, :call
  def call(env)
    env["SERVER_NAME"] = env["HTTP_HOST"]

You can now use Rack::URLMap as usual and it'll work as expected.