Revert "FIX: apply defaults constraints to routes format (#7890)"

Revert “FIX: apply defaults constraints to routes format (#7890)”

This reverts commit 7d01c5de1a92b020e19f387123a3cbbbe969c727.

Trivial get on / was failing with a 404 with this change.

diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 1fc1879..bd0bf7a 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1065,10 +1065,7 @@ class UsersController < ApplicationController
       @confirmed = true
     end
 
-    respond_to do |format|
-      format.json { render json: success_json }
-      format.html { render layout: 'no_ember' }
-    end
+    render layout: 'no_ember'
   end
 
   def list_second_factors
diff --git a/config/routes.rb b/config/routes.rb
index 62e3ae4..48f93e5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -12,8 +12,7 @@ USERNAME_ROUTE_FORMAT = /[%\w.\-]+?/ unless defined? USERNAME_ROUTE_FORMAT
 BACKUP_ROUTE_FORMAT = /.+\.(sql\.gz|tar\.gz|tgz)/i unless defined? BACKUP_ROUTE_FORMAT
 
 Discourse::Application.routes.draw do
-  scope path: nil, constraints: { format: /(json|html)/ } do
-    relative_url_root = (defined?(Rails.configuration.relative_url_root) && Rails.configuration.relative_url_root) ? Rails.configuration.relative_url_root + '/' : '/'
+  relative_url_root = (defined?(Rails.configuration.relative_url_root) && Rails.configuration.relative_url_root) ? Rails.configuration.relative_url_root + '/' : '/'
 
   match "/404", to: "exceptions#not_found", via: [:get, :post]
   get "/404-body" => "exceptions#not_found_body"
@@ -25,15 +24,13 @@ Discourse::Application.routes.draw do
   post "webhooks/sendgrid" => "webhooks#sendgrid"
   post "webhooks/sparkpost" => "webhooks#sparkpost"
 
-  scope path: nil, constraints: { format: /.*/ } do
-    if Rails.env.development?
-      mount Sidekiq::Web => "/sidekiq"
-      mount Logster::Web => "/logs"
-    else
-      # only allow sidekiq in master site
-      mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new(require_master: true)
-      mount Logster::Web => "/logs", constraints: AdminConstraint.new
-    end
+  if Rails.env.development?
+    mount Sidekiq::Web => "/sidekiq"
+    mount Logster::Web => "/logs"
+  else
+    # only allow sidekiq in master site
+    mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new(require_master: true)
+    mount Logster::Web => "/logs", constraints: AdminConstraint.new
   end
 
   resources :about do
@@ -353,17 +350,17 @@ Discourse::Application.routes.draw do
   post "composer/parse_html" => "composer#parse_html"
 
   resources :static
-  post "login" => "static#enter"
-  get "login" => "static#show", id: "login"
-  get "password-reset" => "static#show", id: "password_reset"
-  get "faq" => "static#show", id: "faq"
-  get "tos" => "static#show", id: "tos", as: 'tos'
-  get "privacy" => "static#show", id: "privacy", as: 'privacy'
-  get "signup" => "static#show", id: "signup"
-  get "login-preferences" => "static#show", id: "login"
+  post "login" => "static#enter", constraints: { format: /(json|html)/ }
+  get "login" => "static#show", id: "login", constraints: { format: /(json|html)/ }
+  get "password-reset" => "static#show", id: "password_reset", constraints: { format: /(json|html)/ }
+  get "faq" => "static#show", id: "faq", constraints: { format: /(json|html)/ }
+  get "tos" => "static#show", id: "tos", as: 'tos', constraints: { format: /(json|html)/ }
+  get "privacy" => "static#show", id: "privacy", as: 'privacy', constraints: { format: /(json|html)/ }
+  get "signup" => "static#show", id: "signup", constraints: { format: /(json|html)/ }
+  get "login-preferences" => "static#show", id: "login", constraints: { format: /(json|html)/ }
 
   %w{guidelines rules conduct}.each do |faq_alias|
-    get faq_alias => "static#show", id: "guidelines", as: faq_alias
+    get faq_alias => "static#show", id: "guidelines", as: faq_alias, constraints: { format: /(json|html)/ }
   end
 
   get "my/*path", to: 'users#my_redirect'
@@ -423,8 +420,8 @@ Discourse::Application.routes.draw do
     get "#{root_path}/:username/messages/group/:group_name/archive" => "user_actions#private_messages", constraints: { username: RouteFormat.username, group_name: RouteFormat.username }
     get "#{root_path}/:username/messages/tags/:tag_id" => "user_actions#private_messages", constraints: StaffConstraint.new
     get "#{root_path}/:username.json" => "users#show", constraints: { username: RouteFormat.username }, defaults: { format: :json }
-    get({ "#{root_path}/:username" => "users#show", constraints: { username: RouteFormat.username } }.merge(index == 1 ? { as: 'user' } : {}))
-    put "#{root_path}/:username" => "users#update", constraints: { username: RouteFormat.username }, defaults: { format: :json }
+    get({ "#{root_path}/:username" => "users#show", constraints: { username: RouteFormat.username, format: /(json|html)/ } }.merge(index == 1 ? { as: 'user' } : {}))
+    put "#{root_path}/:username" => "users#update", constraints: { username: RouteFormat.username, format: /(json|html)/ }, defaults: { format: :json }
     get "#{root_path}/:username/emails" => "users#check_emails", constraints: { username: RouteFormat.username }
     get({ "#{root_path}/:username/preferences" => "users#preferences", constraints: { username: RouteFormat.username } }.merge(index == 1 ? { as: :email_preferences } : {}))
     get "#{root_path}/:username/preferences/email" => "users_email#index", constraints: { username: RouteFormat.username }
@@ -466,7 +463,7 @@ Discourse::Application.routes.draw do
     get "#{root_path}/:username/badges" => "users#badges", constraints: { username: RouteFormat.username }
     get "#{root_path}/:username/notifications" => "users#show", constraints: { username: RouteFormat.username }
     get "#{root_path}/:username/notifications/:filter" => "users#show", constraints: { username: RouteFormat.username }
-    delete "#{root_path}/:username" => "users#destroy", constraints: { username: RouteFormat.username }
+    delete "#{root_path}/:username" => "users#destroy", constraints: { username: RouteFormat.username, format: /(json|html)/ }
     get "#{root_path}/by-external/:external_id" => "users#show", constraints: { external_id: /[^\/]+/ }
     get "#{root_path}/:username/flagged-posts" => "users#show", constraints: { username: RouteFormat.username }
     get "#{root_path}/:username/deleted-posts" => "users#show", constraints: { username: RouteFormat.username }
@@ -475,18 +472,18 @@ Discourse::Application.routes.draw do
   end
 
   get "user-badges/:username.json" => "user_badges#username", constraints: { username: RouteFormat.username }, defaults: { format: :json }
-  get "user-badges/:username" => "user_badges#username", constraints: { username: RouteFormat.username }
+  get "user-badges/:username" => "user_badges#username", constraints: { username: RouteFormat.username, format: /(json|html)/ }
 
   post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar", constraints: { username: RouteFormat.username }
-  get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter", constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: RouteFormat.username, format: :png }
-  get "user_avatar/:hostname/:username/:size/:version.png" => "user_avatars#show", constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: RouteFormat.username, format: :png }
+  get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: RouteFormat.username }
+  get "user_avatar/:hostname/:username/:size/:version.png" => "user_avatars#show", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: RouteFormat.username }
 
-  get "letter_avatar_proxy/:version/letter/:letter/:color/:size.png" => "user_avatars#show_proxy_letter", constraints: { format: :png }
+  get "letter_avatar_proxy/:version/letter/:letter/:color/:size.png" => "user_avatars#show_proxy_letter"
 
-  get "svg-sprite/:hostname/svg-:theme_ids-:version.js" => "svg_sprite#show", constraints: { hostname: /[\w\.-]+/, version: /\h{40}/, theme_ids: /([0-9]+(,[0-9]+)*)?/, format: :js }

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

GitHub sha: e8ee3921