mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-28 15:03:58 -04:00
Support 404 routes in the Ember App
This commit is contained in:
parent
f61f29439e
commit
f50039b48b
8 changed files with 54 additions and 26 deletions
app
assets/javascripts/discourse
controllers
views
config
test/javascripts
|
@ -23,17 +23,25 @@ Discourse.Route = Em.Route.extend({
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var routeBuilder;
|
||||||
|
|
||||||
Discourse.Route.reopenClass({
|
Discourse.Route.reopenClass({
|
||||||
|
|
||||||
buildRoutes: function(builder) {
|
buildRoutes: function(builder) {
|
||||||
var oldBuilder = Discourse.routeBuilder;
|
var oldBuilder = routeBuilder;
|
||||||
Discourse.routeBuilder = function() {
|
routeBuilder = function() {
|
||||||
if (oldBuilder) oldBuilder.call(this);
|
if (oldBuilder) oldBuilder.call(this);
|
||||||
return builder.call(this);
|
return builder.call(this);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mapRoutes: function() {
|
||||||
|
Discourse.Router.map(function() {
|
||||||
|
routeBuilder.call(this);
|
||||||
|
this.route('unknown', {path: '*path'});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
cleanDOM: function() {
|
cleanDOM: function() {
|
||||||
// Close mini profiler
|
// Close mini profiler
|
||||||
$('.profiler-results .profiler-result').remove();
|
$('.profiler-results .profiler-result').remove();
|
||||||
|
|
5
app/assets/javascripts/discourse/routes/unknown_route.js
Normal file
5
app/assets/javascripts/discourse/routes/unknown_route.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Discourse.UnknownRoute = Em.Route.extend({
|
||||||
|
model: function() {
|
||||||
|
return Discourse.ajax("/404-body", {dataType: 'html'});
|
||||||
|
}
|
||||||
|
});
|
7
app/assets/javascripts/discourse/views/unknown_view.js
Normal file
7
app/assets/javascripts/discourse/views/unknown_view.js
Normal file
|
@ -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
|
raise Discourse::NotFound
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
Discourse.Environment = '<%= Rails.env %>';
|
Discourse.Environment = '<%= Rails.env %>';
|
||||||
Discourse.SiteSettings = PreloadStore.get('siteSettings');
|
Discourse.SiteSettings = PreloadStore.get('siteSettings');
|
||||||
Discourse.Router = Ember.Router.extend({ location: 'discourse-location' });
|
Discourse.Router = Ember.Router.extend({ location: 'discourse-location' });
|
||||||
Discourse.Router.map(function() { Discourse.routeBuilder.call(this); });
|
Discourse.Route.mapRoutes();
|
||||||
Discourse.start();
|
Discourse.start();
|
||||||
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -21,23 +21,25 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<%- unless @hide_google %>
|
||||||
<div class="span10" style='padding-top: 20px'>
|
<div class="row">
|
||||||
<h2 class="page-not-found-search"><%= t 'page_not_found.search_title' %></h2>
|
<div class="span10" style='padding-top: 20px'>
|
||||||
<p>
|
<h2 class="page-not-found-search"><%= t 'page_not_found.search_title' %></h2>
|
||||||
<form action='//google.com' id='google-search' onsubmit="return google_button_clicked()">
|
<p>
|
||||||
<input type="text" id='user-query' value="<%= @slug %>">
|
<form action='//google.com' id='google-search' onsubmit="return google_button_clicked()">
|
||||||
<input type='hidden' id='google-query' name="q">
|
<input type="text" id='user-query' value="<%= @slug %>">
|
||||||
<button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
|
<input type='hidden' id='google-query' name="q">
|
||||||
</form>
|
<button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
|
||||||
</p>
|
</form>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<script language="Javascript">
|
<script language="Javascript">
|
||||||
function google_button_clicked(e) {
|
function google_button_clicked(e) {
|
||||||
var searchValue = document.getElementById('user-query').value;
|
var searchValue = document.getElementById('user-query').value;
|
||||||
document.getElementById('google-query').value = 'site:<%= local_domain %> ' + searchValue;
|
document.getElementById('google-query').value = 'site:<%= local_domain %> ' + searchValue;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
</script>
|
</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
|
Discourse::Application.routes.draw do
|
||||||
|
|
||||||
match "/404", to: "exceptions#not_found", via: [:get, :post]
|
match "/404", to: "exceptions#not_found", via: [:get, :post]
|
||||||
|
get "/404-body" => "exceptions#not_found_body"
|
||||||
|
|
||||||
mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new
|
mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new
|
||||||
|
|
||||||
|
|
|
@ -79,11 +79,7 @@ Discourse.setupForTesting();
|
||||||
Discourse.injectTestHelpers();
|
Discourse.injectTestHelpers();
|
||||||
Discourse.runInitializers();
|
Discourse.runInitializers();
|
||||||
Discourse.start();
|
Discourse.start();
|
||||||
|
Discourse.Route.mapRoutes();
|
||||||
Discourse.Router.map(function() {
|
|
||||||
Discourse.routeBuilder.call(this);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
QUnit.testStart(function() {
|
QUnit.testStart(function() {
|
||||||
// Allow our tests to change site settings and have them reset before the next test
|
// Allow our tests to change site settings and have them reset before the next test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue