-
Notifications
You must be signed in to change notification settings - Fork 1
/
dispatch_fcgi.rb
executable file
·77 lines (67 loc) · 2.25 KB
/
dispatch_fcgi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
begin
load File.join(File.dirname(File.expand_path(__FILE__)), "env_vals.rb")
rescue LoadError; end
app_name = 'BikeBinder'
user_name = ENV['USER']
ruby_version = ENV['RUBY_INTERPRETER'] || 'default'
ENV['RAILS_ENV'] = 'shared_host'
ENV['HOME'] ||= "/home/#{user_name}"
ENV['GEM_HOME'] = File.expand_path("/home/#{user_name}/.rvm/gems/#{ruby_version}")
ENV['GEM_PATH'] = File.expand_path("/home/#{user_name}/.rvm/gems/#{ruby_version}") + ":" +
File.expand_path("/home/#{user_name}/.rvm/gems/#{ruby_version}@global")
require 'rubygems'
require 'bundler'
Bundler.setup(:default, :fcgi)
require 'rack'
require 'rack/protection'
require 'rack/utf8_sanitizer'
require 'airbrake'
load File.join(File.dirname(File.expand_path(__FILE__)),"initializers", "airbrake.rb")
class Rack::PathInfoRewriter
def initialize(app)
@app = app
end
def call(env)
# Don't delete it--Rack::URLMap assumes it is not nil
env['SCRIPT_NAME'] = ''
pathInfo, query = env['REQUEST_URI'].split('?', 2)
env['PATH_INFO'] = pathInfo
env['QUERY_STRING'] = query
@app.call(env)
end
end
config_fpath = File.expand_path(File.join(File.dirname(__FILE__),
'..', 'config.ru'))
begin
app, options = Rack::Builder.parse_file(config_fpath)
rescue => ex
ENV['airbrake.error_id'] =
error_id = Airbrake.notify_or_ignore(ex,cgi_data: ENV.to_hash)
$stderr.puts "An error was sent to Airbrake with error_id: '#{ENV["airbrake.error_id"]}'"
raise ex
end
wrappedApp = Rack::Builder.new do
use Airbrake::Rack
begin
use Rack::UTF8Sanitizer
use Rack::ShowExceptions
use Rack::PathInfoRewriter
use Rack::Protection::IPSpoofing
rescue => ex
env['airbrake.error_id'] =
Airbrake.notify_or_ignore(ex,cgi_data: ENV.to_hash)
if defined? Rails
Rails.logger.fatal "An error was sent to Airbrake with error_id: '#{env["airbrake.error_id"]}'"
else
$stderr.puts "An error was sent to Airbrake with error_id: '#{env["airbrake.error_id"]}'"
end
end
run app
end
begin
Rack::Handler::FastCGI.run wrappedApp
rescue => ex
ENV['airbrake.error_id'] =
Airbrake.notify_or_ignore(ex,cgi_data: ENV.to_hash)
$stderr.puts "An error was sent to Airbrake with error_id: '#{ENV["airbrake.error_id"]}'"
end