Skip to content

Instantly share code, notes, and snippets.

@techarch
Created May 1, 2010 17:10
Show Gist options
  • Save techarch/386493 to your computer and use it in GitHub Desktop.
Save techarch/386493 to your computer and use it in GitHub Desktop.
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /dispatch.cgi/$1 [QSA,L]
ErrorDocument 500 "Application error: Ruby Camping application failed to start properly
#!/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__) + '/portal.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'] = '/'
begin
@app.call(env)
rescue Exception => ex
msg = '<h1>Error: ' + $! +'</h1><br/><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