Last active
August 29, 2015 14:00
-
-
Save apavlyut/11208591 to your computer and use it in GitHub Desktop.
Ловим на входе в heroku наши домены поддомены и что надо делаем.
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
# lib/heroku_redirect.rb | |
class HerokuRedirect | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
unless request.host.starts_with?("www.") || request.host.starts_with?("start.") || request.host.starts_with?("crm.") || request.host.starts_with?("api.") || request.host.starts_with?("erp.") || request.host.include?("mydomain.com") || request.host.include?("staging.") | |
# puts 'redirecting to www' | |
[301, {"Location" => request.url.sub("//", "//www.")}, self] | |
else | |
# puts "is erp: #{request.host.starts_with?('erp.')}" | |
# puts "is www: #{request.host.starts_with?('www.')}" | |
@app.call(env) | |
end | |
end | |
def each(&block) | |
end | |
end |
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
# config/environments/production.rb | |
# ... | |
config.middleware.use HerokuRedirect |
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
scope module: :api do | |
constraints subdomain: /api(.*)/ do | |
... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment