Proximity
Proximity is a Rack::Proxy router that uses
Journey for routing. Journey is
vendored into ActionPack as of Rails4.
Usage
- Create your own subclass of
Rack::Proxy. -
include Proximityinto that class. - Define
rewrite_envandrewrite_responseas normal.ProximityoverridesRack::Proxy's call so yourenv['HTTP_HOST']andenv['PATH_INFO']will be changed before your call torewrite_env. - If you override
call, ensure you call super. - Create your proxy routes in a
proxies.rbfile and require it in your application.
Example
# my_proxy.rb
class MyProxy < Rack::Proxy
include Proximity
end
# proxies.rb
MyProxy.routes.draw do
route 'example' => 'example.com/api' do
proxy 'active' => 'accounts/active'
proxy 'accounts' => same, formats %w[json csv]
proxy 'accounts/:account_id' => same
proxy 'crazy/:id/:account_id' => 'fluffy/kitties/:id-:account_id'
end
endInstallation
Add this line to your application's Gemfile:
gem 'proximity'
And then execute:
$ bundle
Or install it yourself as:
$ gem install proximity
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request