I found this great blog post on how to use Rack::Proxy
as a separate proxy app. The article explains how he uses Rack::Proxy
to proxy requests to http://localhost:3000
to an app on port 3001
and requests to http://localhost:3000/api
to an app on port 3002
. I want to do the same thing, but I do not want to create a separate proxy app. Instead, I want my main Rails app to proxy requests to /blog
to a different app.
Figured it out.
require 'rack-proxy'
class Proxy < Rack::Proxy
def initialize(app)
@app = app
end
def rewrite_env(env)
# do magic in here
end
end
config.middleware.use "Proxy"