Revert "fix wonky logic figuring out host name"

This reverts commit 114fcb4734.
This commit is contained in:
Sam 2013-05-31 08:41:29 +10:00
parent 114fcb4734
commit 160567e372

View file

@ -1,3 +1,5 @@
require 'cache'
module Discourse
# When they try to do something they should be logged in for
@ -12,29 +14,37 @@ module Discourse
# When something they want is not found
class NotFound < Exception; end
def self.cache
@cache ||= Cache.new
end
# Get the current base URL for the current site
def self.current_hostname
if SiteSetting.force_hostname.present?
SiteSetting.force_hostname
else
RailsMultisite::ConnectionManagement.current_hostname
end
def self.base_uri default_value=""
if !ActionController::Base.config.relative_url_root.blank?
return ActionController::Base.config.relative_url_root
else
return default_value
end
end
def self.base_url_no_prefix
protocol = "http"
protocol = "https" if SiteSetting.use_ssl?
if SiteSetting.force_hostname.present?
result = "#{protocol}://#{SiteSetting.force_hostname}"
else
result = "#{protocol}://#{current_hostname}"
end
result << ":#{SiteSetting.port}" if SiteSetting.port.present? && SiteSetting.port.to_i > 0
result
end
def self.base_url
default_port = 80
protocol = "http"
if SiteSetting.use_ssl?
protocol = "https"
default_port = 443
end
result = "#{protocol}://#{current_hostname}"
if SiteSetting.port.present? && SiteSetting.port.to_i > 0 && SiteSetting.port.to_i != default_port
result << ":#{SiteSetting.port}"
end
result
return base_url_no_prefix + base_uri
end
def self.enable_maintenance_mode
@ -63,6 +73,12 @@ module Discourse
end
end
# Either returns the system_username user or the first admin.
def self.system_user
user = User.where(username_lower: SiteSetting.system_username).first if SiteSetting.system_username.present?
user = User.admins.order(:id).first if user.blank?
user
end
private