Skip to content

Instantly share code, notes, and snippets.

@apavlyut
Last active August 29, 2015 14:00
Show Gist options
  • Save apavlyut/11208591 to your computer and use it in GitHub Desktop.
Save apavlyut/11208591 to your computer and use it in GitHub Desktop.
Ловим на входе в heroku наши домены поддомены и что надо делаем.
# 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
# config/environments/production.rb
# ...
config.middleware.use HerokuRedirect
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