Skip to content

Instantly share code, notes, and snippets.

@techarch
Created May 1, 2010 17:10

Revisions

  1. techarch revised this gist May 1, 2010. 2 changed files with 5 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    Options +FollowSymLinks +ExecCGI
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /dispatch.cgi/$1 [QSA,L]
    RewriteRule ^(.*)$ /dispatch.fcgi/$1 [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]
    ErrorDocument 500 "Application error: Ruby Camping application failed to start properly
    4 changes: 4 additions & 0 deletions dispatch.cgi
    Original file line number Diff line number Diff line change
    @@ -35,6 +35,10 @@ class OneAndOneCGIAdapter
    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
  2. techarch revised this gist May 1, 2010. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions dispatch.cgi
    Original file line number Diff line number Diff line change
    @@ -38,8 +38,10 @@ class OneAndOneCGIAdapter
    begin
    @app.call(env)
    rescue Exception => ex
    msg = '<h1>Error: ' + $! +'</h1><br/><ol>'
    ex.backtrace.each { | t | msg << '<li>' + t + '</li><br/>' }
    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)
  3. techarch revised this gist May 1, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dispatch.cgi
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ require 'camping'

    require 'your_camping_app.rb'

    LOGPATH = File.dirname(__FILE__) + '/portal.log'
    LOGPATH = File.dirname(__FILE__) + '/your_camping_app.log'

    logger = Logger.new(LOGPATH)

  4. techarch revised this gist May 1, 2010. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions dispatch.cgi
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,9 @@ require 'camping'

    require 'your_camping_app.rb'

    logger = Logger.new(File.dirname(__FILE__) + '/your_camping_app.log')
    LOGPATH = File.dirname(__FILE__) + '/portal.log'

    logger = Logger.new(LOGPATH)

    module Rack
    class Request
    @@ -26,8 +28,8 @@ module Rack
    end

    class OneAndOneCGIAdapter
    def initialize(app)
    @app = app
    def initialize(app)
    @app = app
    end

    def call(env)
    @@ -40,6 +42,7 @@ class OneAndOneCGIAdapter
    ex.backtrace.each { | t | msg << '<li>' + t + '</li><br/>' }
    msg << '</ol>'

    logger = Logger.new(LOGPATH)
    logger.error msg

    [200,{"Content-Type" => "text/html"},msg]
  5. techarch created this gist May 1, 2010.
    5 changes: 5 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    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
    53 changes: 53 additions & 0 deletions dispatch.cgi
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #!/usr/bin/ruby

    Dir.chdir '/path/to/your/camping/app'

    require 'rubygems'
    require 'rack'
    require 'camping'

    require 'your_camping_app.rb'

    logger = Logger.new(File.dirname(__FILE__) + '/your_camping_app.log')

    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.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