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 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
@ -12,31 +14,39 @@ 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? RailsMultisite::ConnectionManagement.current_hostname
SiteSetting.force_hostname end
def self.base_uri default_value=""
if !ActionController::Base.config.relative_url_root.blank?
return ActionController::Base.config.relative_url_root
else else
RailsMultisite::ConnectionManagement.current_hostname return default_value
end end
end end
def self.base_url def self.base_url_no_prefix
default_port = 80
protocol = "http" protocol = "http"
if SiteSetting.use_ssl? protocol = "https" if SiteSetting.use_ssl?
protocol = "https" if SiteSetting.force_hostname.present?
default_port = 443 result = "#{protocol}://#{SiteSetting.force_hostname}"
end else
result = "#{protocol}://#{current_hostname}"
result = "#{protocol}://#{current_hostname}"
if SiteSetting.port.present? && SiteSetting.port.to_i > 0 && SiteSetting.port.to_i != default_port
result << ":#{SiteSetting.port}"
end end
result << ":#{SiteSetting.port}" if SiteSetting.port.present? && SiteSetting.port.to_i > 0
result result
end end
def self.base_url
return base_url_no_prefix + base_uri
end
def self.enable_maintenance_mode def self.enable_maintenance_mode
$redis.set maintenance_mode_key, 1 $redis.set maintenance_mode_key, 1
true true
@ -63,6 +73,12 @@ 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