Replace `base_uri` with `base_path` (#10879)

Replace base_uri with base_path (#10879)

DEV: Replace instances of Discourse.base_uri with Discourse.base_path

This is clearer because the base_uri is actually just a path prefix. This continues the work started in 555f467.

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index afba6bb..672280d 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -329,7 +329,7 @@ class ApplicationController < ActionController::Base
         current_user.reload
         current_user.publish_notifications_state
         cookie_args = {}
-        cookie_args[:path] = Discourse.base_uri if Discourse.base_uri.present?
+        cookie_args[:path] = Discourse.base_path if Discourse.base_path.present?
         cookies.delete('cn', cookie_args)
       end
     end
diff --git a/app/controllers/extra_locales_controller.rb b/app/controllers/extra_locales_controller.rb
index e20c81e..314e432 100644
--- a/app/controllers/extra_locales_controller.rb
+++ b/app/controllers/extra_locales_controller.rb
@@ -45,7 +45,7 @@ class ExtraLocalesController < ApplicationController
   end
 
   def self.url(bundle)
-    "#{Discourse.base_uri}/extra-locales/#{bundle}?v=#{bundle_js_hash(bundle)}"
+    "#{Discourse.base_path}/extra-locales/#{bundle}?v=#{bundle_js_hash(bundle)}"
   end
 
   def self.client_overrides_exist?
diff --git a/app/controllers/robots_txt_controller.rb b/app/controllers/robots_txt_controller.rb
index 90fdb28..7de0793 100644
--- a/app/controllers/robots_txt_controller.rb
+++ b/app/controllers/robots_txt_controller.rb
@@ -45,8 +45,8 @@ class RobotsTxtController < ApplicationController
   end
 
   def self.fetch_default_robots_info
-    deny_paths = DISALLOWED_PATHS.map { |p| Discourse.base_uri + p }
-    deny_all = [ "#{Discourse.base_uri}/" ]
+    deny_paths = DISALLOWED_PATHS.map { |p| Discourse.base_path + p }
+    deny_all = [ "#{Discourse.base_path}/" ]
 
     result = {
       header: "# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file",
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 2dfa106..c6e5810 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -478,7 +478,7 @@ class TagsController < ::ApplicationController
     permalink = Permalink.find_by_url(url)
 
     if permalink.present? && permalink.category_id
-      redirect_to "#{Discourse::base_uri}/tags#{permalink.target_url}/#{params[:tag_id]}", status: :moved_permanently
+      redirect_to "#{Discourse.base_path}/tags#{permalink.target_url}/#{params[:tag_id]}", status: :moved_permanently
     else
       # redirect to 404
       raise Discourse::NotFound
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb
index 674c39b..854acb4 100644
--- a/app/controllers/users/omniauth_callbacks_controller.rb
+++ b/app/controllers/users/omniauth_callbacks_controller.rb
@@ -32,7 +32,7 @@ class Users::OmniauthCallbacksController < ApplicationController
       # Save to redis, with a secret token, then redirect to confirmation screen
       token = SecureRandom.hex
       Discourse.redis.setex "#{Users::AssociateAccountsController::REDIS_PREFIX}_#{current_user.id}_#{token}", 10.minutes, auth.to_json
-      return redirect_to "#{Discourse.base_uri}/associate/#{token}"
+      return redirect_to "#{Discourse.base_path}/associate/#{token}"
     else
       @auth_result = authenticator.after_authenticate(auth)
       DiscourseEvent.trigger(:after_auth, authenticator, @auth_result)
@@ -55,14 +55,14 @@ class Users::OmniauthCallbacksController < ApplicationController
 
       if parsed && # Valid
          (parsed.host == nil || parsed.host == Discourse.current_hostname) && # Local
-         !parsed.path.starts_with?("#{Discourse.base_uri}/auth/") # Not /auth URL
+         !parsed.path.starts_with?("#{Discourse.base_path}/auth/") # Not /auth URL
         @origin = +"#{parsed.path}"
         @origin << "?#{parsed.query}" if parsed.query
       end
     end
 
     if @origin.blank?
-      @origin = Discourse.base_uri("/")
+      @origin = Discourse.base_path("/")
     end
 
     @auth_result.destination_url = @origin
@@ -76,7 +76,7 @@ class Users::OmniauthCallbacksController < ApplicationController
       cookies['_bypass_cache'] = true
       cookies[:authentication_data] = {
         value: @auth_result.to_client_hash.to_json,
-        path: Discourse.base_uri("/")
+        path: Discourse.base_path("/")
       }
       redirect_to @origin
     end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index bd160ba..84a2b28 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -300,7 +300,7 @@ module ApplicationHelper
   end
 
   def login_path
-    "#{Discourse::base_uri}/login"
+    "#{Discourse.base_path}/login"
   end
 
   def mobile_view?
@@ -488,7 +488,7 @@ module ApplicationHelper
     setup_data = {
       cdn: Rails.configuration.action_controller.asset_host,
       base_url: Discourse.base_url,
-      base_uri: Discourse::base_uri,
+      base_uri: Discourse.base_path,
       environment: Rails.env,
       letter_avatar_version: LetterAvatar.version,
       markdown_it_url: script_asset_path('markdown-it-bundle'),
diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb
index ffbf735..e2f3f05 100644
--- a/app/helpers/user_notifications_helper.rb
+++ b/app/helpers/user_notifications_helper.rb
@@ -98,11 +98,11 @@ module UserNotificationsHelper
   end
 
   def email_image_url(basename)
-    UrlHelper.absolute("#{Discourse.base_uri}/images/emails/#{basename}")
+    UrlHelper.absolute("#{Discourse.base_path}/images/emails/#{basename}")
   end
 
   def url_for_email(href)
-    URI(href).host.present? ? href : UrlHelper.absolute("#{Discourse.base_uri}#{href}")
+    URI(href).host.present? ? href : UrlHelper.absolute("#{Discourse.base_path}#{href}")
   rescue URI::Error
     href
   end
diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb
index 889be79..79fe3fe 100644
--- a/app/models/admin_dashboard_data.rb
+++ b/app/models/admin_dashboard_data.rb
@@ -200,7 +200,7 @@ class AdminDashboardData
   end
 
   def subfolder_ends_in_slash_check
-    I18n.t('dashboard.subfolder_ends_in_slash') if Discourse.base_uri =~ /\/$/
+    I18n.t('dashboard.subfolder_ends_in_slash') if Discourse.base_path =~ /\/$/
   end
 
   def pop3_polling_configuration
diff --git a/app/models/badge.rb b/app/models/badge.rb
index 69d06de..92e02a5 100644
--- a/app/models/badge.rb
+++ b/app/models/badge.rb
@@ -263,7 +263,7 @@ class Badge < ActiveRecord::Base
 
   def long_description
     key = "badges.#{i18n_name}.long_description"
-    I18n.t(key, default: self[:long_description] || '', base_uri: Discourse.base_uri, max_likes_per_day: SiteSetting.max_likes_per_day)
+    I18n.t(key, default: self[:long_description] || '', base_uri: Discourse.base_path, max_likes_per_day: SiteSetting.max_likes_per_day)
   end
 
   def long_description=(val)
@@ -273,7 +273,7 @@ class Badge < ActiveRecord::Base
 
   def description
     key = "badges.#{i18n_name}.description"
-    I18n.t(key, default: self[:description] || '', base_uri: Discourse.base_uri, max_likes_per_day: SiteSetting.max_likes_per_day)
+    I18n.t(key, default: self[:description] || '', base_uri: Discourse.base_path, max_likes_per_day: SiteSetting.max_likes_per_day)
   end
 
   def description=(val)
diff --git a/app/models/category.rb b/app/models/category.rb
index 91daf8e..48715f4 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -724,7 +724,7 @@ class Category < ActiveRecord::Base
   end
 
   def full_slug(separator = "-")
-    start_idx = "#{Discourse.base_uri}/c/".size
+    start_idx = "#{Discourse.base_path}/c/".size
     url[start_idx..-1].gsub("/", separator)
   end
 
@@ -735,7 +735,7 @@ class Category < ActiveRecord::Base
   end
 
   def url
-    @@url_cache[self.id] ||= "#{Discourse.base_uri}/c/#{slug_path.join('/')}/#{self.id}"

[... diff too long, it was truncated ...]

GitHub sha: 721ee364

1 Like

This commit appears in #10879 which was approved by davidtaylorhq, davidtaylorhq, and davidtaylorhq. It was merged by danielwaterworth.