Skip to content

Instantly share code, notes, and snippets.

@dblock
Created December 11, 2012 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dblock/4263488 to your computer and use it in GitHub Desktop.
Save dblock/4263488 to your computer and use it in GitHub Desktop.
Conditionally disable the proxy forwarding by https://github.com/dblock/heroku-forward using the DISABLE_FORWARD_PROXY environment setting.
require 'rubygems'
require 'bundler'
if ENV['DISABLE_FORWARD_PROXY']
eval File.read(::File.expand_path('../my_app.ru', __FILE__))
else
$stdout.sync = true
Bundler.require(:rack)
port = (ARGV.first || ENV['PORT'] || 3000).to_i
env = ENV['RACK_ENV'] || 'development'
require 'em-proxy'
require 'logger'
require 'heroku-forward'
#
# Setup a reverse proxy for faster Heroku boot and future load-balancing.
#
application = File.expand_path('../my_app.ru', __FILE__)
backend = Heroku::Forward::Backends::Thin.new(application: application, env: env)
proxy = Heroku::Forward::Proxy::Server.new(backend, { host: '0.0.0.0', port: port })
proxy.logger = Logger.new(STDOUT)
proxy.forward!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment