mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 20:36:39 +08:00
fix wonky logic figuring out host name
This commit is contained in:
parent
42714b424f
commit
114fcb4734
|
@ -1,5 +1,3 @@
|
|||
require 'cache'
|
||||
|
||||
module Discourse
|
||||
|
||||
# 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
|
||||
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
|
||||
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
|
||||
|
||||
def self.enable_maintenance_mode
|
||||
|
@ -73,12 +63,6 @@ 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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user