PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, June 24, 2022

[FIXED] How do I use Rack::Proxy within Rails to proxy requests to a specific path to another app

 June 24, 2022     proxy, rack, reverse-proxy, routes, ruby-on-rails-3.1     No comments   

Issue

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.

Blog Post: http://livsey.org/blog/2012/02/23/using-rack-proxy-to-serve-multiple-rails-apps-from-the-same-domain-and-port/


Solution

Figured it out.

lib/proxy.rb

require 'rack-proxy'
class Proxy < Rack::Proxy
    def initialize(app)
        @app = app
    end

    def rewrite_env(env)
        # do magic in here
    end
end

config/application.rb

config.middleware.use "Proxy"


Answered By - John
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing