Skip to content

Instantly share code, notes, and snippets.

@mgamba
Last active August 29, 2015 14:07
Show Gist options
  • Save mgamba/1b18c4e1a57d284d8067 to your computer and use it in GitHub Desktop.
Save mgamba/1b18c4e1a57d284d8067 to your computer and use it in GitHub Desktop.
require 'rack-proxy'
require 'rack'
RemoteHostForName = {
'simple' => "localhost:4567"
}
class ExternalProxy < Rack::Proxy
def rewrite_env(env)
#request = Rack::Request.new(env)
path_params = env["action_dispatch.request.path_parameters"]
env["HTTP_HOST"] = RemoteHostForName[path_params[:remote_name]]
env["SCRIPT_NAME"] = '/'+path_params[:remote_path]
env
end
end
RailsProxy::Application.routes.draw do
mount ExternalProxy.new, at: "/proxy/:remote_name/*remote_path"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment