Project

proximity

0.0
No commit activity in last 3 years
No release in over 3 years
Rack::Proxy router using Journey
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0

Runtime

 Project Readme

Proximity

Proximity is a Rack::Proxy router that uses Journey for routing. Journey is vendored into ActionPack as of Rails4.

Gem Version Code Climate Build Status Coverage Status Dependency Status

Usage

  1. Create your own subclass of Rack::Proxy.
  2. include Proximity into that class.
  3. Define rewrite_env and rewrite_response as normal. Proximity overrides Rack::Proxy's call so your env['HTTP_HOST'] and env['PATH_INFO'] will be changed before your call to rewrite_env.
  4. If you override call, ensure you call super.
  5. Create your proxy routes in a proxies.rb file 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
end

Installation

Add this line to your application's Gemfile:

gem 'proximity'

And then execute:

$ bundle

Or install it yourself as:

$ gem install proximity

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Thanks

  1. Much goes to TMA for many awesome projects
  2. wzcolon for pairing with when gemifying this
  3. nathanl for encouraging me to gemify this