Skip to content

Instantly share code, notes, and snippets.

@noverloop
Created March 26, 2012 10:03
Show Gist options
  • Save noverloop/2204258 to your computer and use it in GitHub Desktop.
Save noverloop/2204258 to your computer and use it in GitHub Desktop.
modifications needed to act as buffering reverse proxy on heroku
$stdout.sync = true
require ::File.expand_path('../config/environment', __FILE__)
run AppName::Application
require 'rubygems'
require 'bundler'
$stdout.sync = true
Bundler.require(:rack)
puts ARGV
$port = ARGV.first
SERVERS = 1
ROOT = '.'
spawn("foreman start worker")
require './proxy'
# Start proxy
BalancingProxy::Server.run
web: ruby config.ru $PORT
worker: bundle exec thin start -R app_name.ru --socket tmp/thin.sock -e production
module Server
def run(host='0.0.0.0')
puts "Launching proxy at #{host}:#{$port}...\n"
Proxy.start(:host => host, :port => $port, :debug => false) do |conn|
Backend.select do |backend|
@connection_process = Proc.new do |backend,count|
begin
conn.server backend, :socket => backend.socket
conn.on_connect &Callbacks.on_connect
conn.on_data &Callbacks.on_data
conn.on_response &Callbacks.on_response
conn.on_finish &Callbacks.on_finish
rescue RuntimeError
unless count > 4
EM.add_timer(20) do
@connection_process.call backend, (count+1)
end
end
end
end
@connection_process.call backend, 0
end
end
end
module_function :run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment