Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.