HTTP Proxy in Rails
Sometimes you want to hide a backend system behind a frontend Rails app without using nginx and likes. I’ll leave a discussion why it’s a bad idea until the next time.
Today I’m going to show you how you can use a Rack lib to do just that.
First of all, add this line to your
Then run your
At this point you have the gem installed. Now you have to create a Rack worker, which you’ll mount in your
routes.rb file later.
lib/ and create
Now let’s mount our new proxy! In your
routes.rb add these lines:
Now if we go to
http://localhost:3000/rails/proxy/test, our request will be redirected to
http://example.com/test. Pretty neat, eh? :)