diff --git a/app/assets/javascripts/discourse/routes/discourse_route.js b/app/assets/javascripts/discourse/routes/discourse_route.js index a4ba03ee2b5..ceade553f7c 100644 --- a/app/assets/javascripts/discourse/routes/discourse_route.js +++ b/app/assets/javascripts/discourse/routes/discourse_route.js @@ -23,17 +23,25 @@ Discourse.Route = Em.Route.extend({ }); +var routeBuilder; Discourse.Route.reopenClass({ buildRoutes: function(builder) { - var oldBuilder = Discourse.routeBuilder; - Discourse.routeBuilder = function() { + var oldBuilder = routeBuilder; + routeBuilder = function() { if (oldBuilder) oldBuilder.call(this); return builder.call(this); }; }, + mapRoutes: function() { + Discourse.Router.map(function() { + routeBuilder.call(this); + this.route('unknown', {path: '*path'}); + }); + }, + cleanDOM: function() { // Close mini profiler $('.profiler-results .profiler-result').remove(); diff --git a/app/assets/javascripts/discourse/routes/unknown_route.js b/app/assets/javascripts/discourse/routes/unknown_route.js new file mode 100644 index 00000000000..06360a7f167 --- /dev/null +++ b/app/assets/javascripts/discourse/routes/unknown_route.js @@ -0,0 +1,5 @@ +Discourse.UnknownRoute = Em.Route.extend({ + model: function() { + return Discourse.ajax("/404-body", {dataType: 'html'}); + } +}); diff --git a/app/assets/javascripts/discourse/views/unknown_view.js b/app/assets/javascripts/discourse/views/unknown_view.js new file mode 100644 index 00000000000..59206b08528 --- /dev/null +++ b/app/assets/javascripts/discourse/views/unknown_view.js @@ -0,0 +1,7 @@ +Discourse.UnknownView = Em.View.extend({ + classNameBindings: [':container'], + + render: function(buffer) { + buffer.push(this.get('controller.model')); + } +}); diff --git a/app/controllers/exceptions_controller.rb b/app/controllers/exceptions_controller.rb index 6a81de159eb..1e28bef5e7f 100644 --- a/app/controllers/exceptions_controller.rb +++ b/app/controllers/exceptions_controller.rb @@ -6,4 +6,13 @@ class ExceptionsController < ApplicationController raise Discourse::NotFound end + # Give us an endpoint to use for 404 content in the ember app + def not_found_body + + # Don't show google search if it's embedded in the Ember app + @hide_google = true + + render text: build_not_found_page(200, false) + end + end diff --git a/app/views/common/_discourse_javascript.html.erb b/app/views/common/_discourse_javascript.html.erb index 41f259dea2a..05cbaab6e84 100644 --- a/app/views/common/_discourse_javascript.html.erb +++ b/app/views/common/_discourse_javascript.html.erb @@ -36,7 +36,7 @@ Discourse.Environment = '<%= Rails.env %>'; Discourse.SiteSettings = PreloadStore.get('siteSettings'); Discourse.Router = Ember.Router.extend({ location: 'discourse-location' }); - Discourse.Router.map(function() { Discourse.routeBuilder.call(this); }); + Discourse.Route.mapRoutes(); Discourse.start(); Discourse.set('assetVersion','<%= Discourse.assets_digest %>'); diff --git a/app/views/exceptions/not_found.html.erb b/app/views/exceptions/not_found.html.erb index 3bf5e23d57c..558f87184f2 100644 --- a/app/views/exceptions/not_found.html.erb +++ b/app/views/exceptions/not_found.html.erb @@ -21,23 +21,25 @@ -
-
- -

-

-

+<%- unless @hide_google %> +
+
+ +

+

+

+
-
- + +<%- end %> diff --git a/config/routes.rb b/config/routes.rb index 7349256d205..3531fe3899f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,7 @@ BACKUP_ROUTE_FORMAT = /[a-zA-Z0-9\-_]*\d{4}(-\d{2}){2}-\d{6}\.tar\.gz/i unless d Discourse::Application.routes.draw do match "/404", to: "exceptions#not_found", via: [:get, :post] + get "/404-body" => "exceptions#not_found_body" mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js index 9889c238dfe..f12211d1184 100644 --- a/test/javascripts/test_helper.js +++ b/test/javascripts/test_helper.js @@ -79,11 +79,7 @@ Discourse.setupForTesting(); Discourse.injectTestHelpers(); Discourse.runInitializers(); Discourse.start(); - -Discourse.Router.map(function() { - Discourse.routeBuilder.call(this); -}); - +Discourse.Route.mapRoutes(); QUnit.testStart(function() { // Allow our tests to change site settings and have them reset before the next test