6

I'm developing a Rails application that uses an API backend for AJAX requests written with Sinatra.

The API runs separately from Rails:

Rails: localhost:3000
API: localhost:9393

In production, we'll be proxying requests to the API with nginx.

The problem is that we don't have nginx in development mode, we're using thin. So I need some sort of Rack middleware that I can add in development mode to proxy the requests for me.

Can someone give me an example of how to do this?

Adam Lassek
  • 35,156
  • 14
  • 91
  • 107

1 Answers1

5

Perhaps Rack::Proxy:

http://coderack.org/users/cwninja/middlewares/18-rackproxy

use Rack::Proxy do |req|
  if req.path =~ %r{identify api request with regex here}
    URI.parse("http://localhost:9393/#{req.fullpath}")
  end
end
minikomi
  • 8,363
  • 3
  • 44
  • 51