Created
March 22, 2013 18:22
-
-
Save jsierles/5223561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'em-proxy' | |
TARGET = ARGV[0] ? ARGV[0].to_sym : :mysql | |
puts "Starting proxy on port 4000." | |
puts "Passing requests port 4100 (mysql) and port 4200 (postgres). Responses are returned from #{TARGET}." | |
Proxy.start(:host => "0.0.0.0", :port => 4000, :debug => true) do |conn| | |
@start = Time.now | |
@data = Hash.new("") | |
conn.server :mysql, :host => "127.0.0.1", :port => 4100 | |
conn.server :postgres, :host => "127.0.0.1", :port => 4200 | |
conn.on_data do |data| | |
data | |
end | |
conn.on_response do |server, resp| | |
# only render response from production | |
@data[server] += resp | |
p "Response delivered from #{TARGET}" if ENV['DEBUG'] | |
resp if server == TARGET | |
end | |
conn.on_finish do |name| | |
p [:on_finish, name, Time.now - @start] if ENV['DEBUG'] | |
p @data if ENV['DEBUG'] | |
:close if name == TARGET | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment