fix wonky logic figuring out host name

This commit is contained in:
Sam 2013-05-31 08:39:52 +10:00
parent 42714b424f
commit 114fcb4734

View File

@ -1,5 +1,3 @@
require 'cache'
module Discourse module Discourse
# When they try to do something they should be logged in for # When they try to do something they should be logged in for
@ -14,37 +12,29 @@ module Discourse
# When something they want is not found # When something they want is not found
class NotFound < Exception; end class NotFound < Exception; end
def self.cache
@cache ||= Cache.new
end
# Get the current base URL for the current site # Get the current base URL for the current site
def self.current_hostname def self.current_hostname
if SiteSetting.force_hostname.present?
SiteSetting.force_hostname
else
RailsMultisite::ConnectionManagement.current_hostname RailsMultisite::ConnectionManagement.current_hostname
end 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 end
def self.base_url def self.base_url
return base_url_no_prefix + base_uri 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
end end
def self.enable_maintenance_mode def self.enable_maintenance_mode
@ -73,12 +63,6 @@ module Discourse
end end
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 private