Created
May 1, 2010 17:10
-
-
Save techarch/386493 to your computer and use it in GitHub Desktop.
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
Options +FollowSymLinks +ExecCGI | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ /dispatch.fcgi/$1 [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L] | |
ErrorDocument 500 "Application error: Ruby Camping application failed to start properly |
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/ruby | |
Dir.chdir '/path/to/your/camping/app' | |
require 'rubygems' | |
require 'rack' | |
require 'camping' | |
require 'your_camping_app.rb' | |
LOGPATH = File.dirname(__FILE__) + '/your_camping_app.log' | |
logger = Logger.new(LOGPATH) | |
module Rack | |
class Request | |
alias :original_rack_POST :POST | |
def POST | |
begin | |
original_rack_POST | |
rescue Errno::ESPIPE | |
@env["rack.request.form_hash"] | |
end | |
end | |
end | |
end | |
class OneAndOneCGIAdapter | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
env['SCRIPT_NAME'] = '/' | |
# Assuming your .htaccess has: | |
# RewriteRule ^(.*)$ /dispatch.fcgi/$1 [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L] | |
env['HTTP_AUTHORIZATION'] = env['REDIRECT_REDIRECT_HTTP_AUTHORIZATION'] || '' | |
begin | |
@app.call(env) | |
rescue Exception => ex | |
msg = "<h1>Error: #{$!}</h1>" | |
msg << "<p>#{Time.now}</p>" | |
msg << '<ol>' | |
ex.backtrace.each { | t | msg << "<li>#{t}</li><br/>" } | |
msg << '</ol>' | |
logger = Logger.new(LOGPATH) | |
logger.error msg | |
[200,{"Content-Type" => "text/html"},msg] | |
end | |
end | |
end | |
adapter = OneAndOneCGIAdapter.new(YourCampingApp) | |
logger.info "start request for #{ENV['SCRIPT_URI']}" | |
Rack::Handler::CGI.run adapter , :Port => 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment