Created
March 6, 2013 15:24
-
-
Save ntalbott/5100053 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ENV["STITCH"] == "1" | |
| require "rack-proxy" | |
| class Stitcher < Rack::Proxy | |
| EXACT = %w(/ /terms /privacy) | |
| PREFIX = %w(/pricing /about /support /gateways /assets) | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) | |
| original_host = env["HTTP_HOST"] | |
| rewrite_env(env) | |
| if env["HTTP_HOST"] != original_host | |
| rewrite_response(perform_request(env)) | |
| else | |
| @app.call(env) | |
| end | |
| end | |
| def rewrite_env(env) | |
| request = Rack::Request.new(env) | |
| return env unless(request.host == ENV["PUBLIC_FULL_DOMAIN"]) | |
| unless( | |
| EXACT.include?(request.path) || | |
| EXACT.include?(request.path + "/") || | |
| PREFIX.include?(request.path) || | |
| PREFIX.any?{|prefix| request.path.starts_with?(prefix + "/")}) | |
| env["HTTP_HOST"] = ENV["SUBSCRIPTIONS_INTERNAL_DOMAIN"] | |
| end | |
| env | |
| end | |
| def extract_http_request_headers(env) | |
| headers = super | |
| headers["Host"] = ENV["PUBLIC_FULL_DOMAIN"] | |
| headers | |
| end | |
| end | |
| Rails.application.middleware.insert_before ActionDispatch::Static, Stitcher | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment