How are AJAX proxies with Rack middleware?

I am developing a Rails application that uses the API backend for AJAX requests written using Sinatra.

The API works separately from Rails:

Rails: localhost:3000
API: localhost:9393

During production, we will proxy API requests using nginx.

The problem is that we do not have nginx in development mode, we use thin. So I need some kind of Rack middleware that I can add in development mode to proxy requests for me.

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

+6
source share
1 answer

Maybe 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 
+5
source

Source: https://habr.com/ru/post/905664/


All Articles