Created
November 7, 2017 09:19
-
-
Save palkan/c5b19d1a09ac63a0d9b08111877b1f99 to your computer and use it in GitHub Desktop.
RackRewriteConfig
This file contains 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
class RackRewriteConfig | |
class << self | |
# Configure named rewrite rule | |
def configure(name, &block) | |
raise ArgumentError, "Block is required" unless block_given? | |
rules[name] = block | |
end | |
# Apply named rule to the target | |
def apply(target, name, *args) | |
raise "Rule not found #{name}" unless rules.key?(name) | |
target.instance_exec(*args, &rules[name]) | |
end | |
private | |
def rules | |
@rules ||= {} | |
end | |
end | |
end |
This file contains 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
Rails.application.configure do | |
config.middleware.insert_before(Rack::Runtime, Rack::Rewrite) do | |
LegacyRoutes.apply(self, :domain_redirect, host: 'bulls.com', target: 'https://www.bulls.com') | |
LegacyRoutes.apply(self, :legacy_callbacks, host: 'cows.com', target: 'callbacks.bulls.com') | |
LegacyRoutes.apply(self, :legacy_callbacks, host: 'www.cows.com', target: 'callbacks.bulls.com') | |
LegacyRoutes.apply(self, :domain_redirect, host: 'cows.com', target: 'https://www.bulls.com') | |
LegacyRoutes.apply(self, :domain_redirect, host: 'www.cows.com', target: 'https://www.bulls.com') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment