Created
March 30, 2011 01:23
-
-
Save shurizzle/893694 to your computer and use it in GitHub Desktop.
FastCGI dispatcher for Padrino in ruby 1.9.x (needed for lighty)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# require rack fastcgi {{{ | |
require 'rack/handler/fastcgi' | |
# support for ruby 1.9.x {{{ | |
class FCGI; class ValuesRecord | |
def self::read_length(buf) | |
if buf.getbyte(0) >> 7 == 0 | |
buf.slice!(0, 1).getbyte(0) | |
else | |
buf.slice!(0, 4).unpack('N')[0] & ((1 << 31) - 1) | |
end | |
end | |
end; end | |
# }}} | |
# }}} | |
# Magic things {{{ | |
module Kernel | |
def suppress_warnings | |
tmp, $VERBOSE = $VERBOSE, nil | |
result = yield | |
$VERBOSE = tmp | |
return result | |
end | |
end | |
# }}} | |
Kernel.suppress_warnings { # because rack redefine some constants | |
require ::File.dirname(__FILE__) + '/config/boot.rb' | |
} | |
# Correcting dumbness {{{ | |
module Padrino; class Router | |
alias __real_call__ call | |
def call(env) | |
self.__real_call__(env.merge!( | |
'SCRIPT_NAME' => "", | |
'PATH_INFO' => File.join(env['SCRIPT_NAME'], env['PATH_INFO'].to_s) | |
)) | |
end | |
end; end | |
# }}} | |
Rack::Handler::FastCGI.run(Padrino.application) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm pleased, thanks