Support 404 routes in the Ember App
This commit is contained in:
parent
f61f29439e
commit
f50039b48b
|
@ -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();
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
Discourse.UnknownRoute = Em.Route.extend({
|
||||
model: function() {
|
||||
return Discourse.ajax("/404-body", {dataType: 'html'});
|
||||
}
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
Discourse.UnknownView = Em.View.extend({
|
||||
classNameBindings: [':container'],
|
||||
|
||||
render: function(buffer) {
|
||||
buffer.push(this.get('controller.model'));
|
||||
}
|
||||
});
|
|
@ -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
|
||||
|
|
|
@ -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 %>');
|
||||
</script>
|
||||
|
|
|
@ -21,23 +21,25 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="span10" style='padding-top: 20px'>
|
||||
<h2 class="page-not-found-search"><%= t 'page_not_found.search_title' %></h2>
|
||||
<p>
|
||||
<form action='//google.com' id='google-search' onsubmit="return google_button_clicked()">
|
||||
<input type="text" id='user-query' value="<%= @slug %>">
|
||||
<input type='hidden' id='google-query' name="q">
|
||||
<button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
|
||||
</form>
|
||||
</p>
|
||||
<%- unless @hide_google %>
|
||||
<div class="row">
|
||||
<div class="span10" style='padding-top: 20px'>
|
||||
<h2 class="page-not-found-search"><%= t 'page_not_found.search_title' %></h2>
|
||||
<p>
|
||||
<form action='//google.com' id='google-search' onsubmit="return google_button_clicked()">
|
||||
<input type="text" id='user-query' value="<%= @slug %>">
|
||||
<input type='hidden' id='google-query' name="q">
|
||||
<button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
|
||||
</form>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script language="Javascript">
|
||||
function google_button_clicked(e) {
|
||||
var searchValue = document.getElementById('user-query').value;
|
||||
document.getElementById('google-query').value = 'site:<%= local_domain %> ' + searchValue;
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
<script language="Javascript">
|
||||
function google_button_clicked(e) {
|
||||
var searchValue = document.getElementById('user-query').value;
|
||||
document.getElementById('google-query').value = 'site:<%= local_domain %> ' + searchValue;
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
<%- end %>
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue