module Rails::LocalSubdomain

Redirects to a specified domain (or ‘’lvh.me’‘ if not provided) when Rails is running in an LocalSubdomain.enabled_environments environment.

Constants

VERSION

Public Class Methods

enabled_environments() click to toggle source

Should be monkey-patched to configure which Rails environments will have lvh.me subdomain support.

# File lib/rails/local_subdomain.rb, line 17
def self.enabled_environments
  %w(development test)
end
enabled_in?(env) click to toggle source
# File lib/rails/local_subdomain.rb, line 21
def self.enabled_in?(env)
  enabled_environments.include?(env)
end

Public Instance Methods

lvh_me_domain() click to toggle source
# File lib/rails/local_subdomain.rb, line 25
def lvh_me_domain
  'lvh.me'
end
lvh_me_path() click to toggle source
# File lib/rails/local_subdomain.rb, line 29
def lvh_me_path
  request.env['ORIGINAL_FULLPATH']
end
lvh_me_port() click to toggle source
# File lib/rails/local_subdomain.rb, line 33
def lvh_me_port
  request.env['SERVER_PORT']
end
lvh_me_protocol() click to toggle source
# File lib/rails/local_subdomain.rb, line 37
def lvh_me_protocol
  request.env['rack.url_scheme']
end
lvh_me_url() click to toggle source
# File lib/rails/local_subdomain.rb, line 41
def lvh_me_url
  "#{lvh_me_protocol}://#{lvh_me_domain}"\
  "#{lvh_me_port == '80' ? '' : ':' + lvh_me_port}#{lvh_me_path}"
end
redirect_to_lvh_me() click to toggle source
# File lib/rails/local_subdomain.rb, line 46
def redirect_to_lvh_me
  return unless LocalSubdomain.enabled_in?(Rails.env)
  return if served_by_lvh_me?

  redirect_to(lvh_me_url)
end
served_by_lvh_me?() click to toggle source
# File lib/rails/local_subdomain.rb, line 53
def served_by_lvh_me?
  !request.env['SERVER_NAME'][/#{lvh_me_domain}$/].nil?
end