Skip to content

Commit

Permalink
Add 404 page. Prevent delete button from changing URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik Viswanathan committed Jul 23, 2012
1 parent 42256e4 commit 3304d5e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
8 changes: 8 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,13 @@ exports.updateObject = function(req, curObject, allowedFields) {
return false;
};

/* Render a 404 response page.
* Requires: web request, web response
*/
exports.render404 = function(req, res) {
res.status(404);
res.render('not-found', { pageId: 'not-found' });
};

/* No operation placeholder for empty callbacks */
exports.noop = function() {};
1 change: 1 addition & 0 deletions public/javascripts/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ function NapkinClient(window, document, $, data, undefined) {

// remove element when delete button is clicked
removeElement: function(event) {
event.preventDefault();
this.layoutView.trigger('removeElement');
},

Expand Down
7 changes: 4 additions & 3 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ var screens = require('../lib/screens');
var components = require('../lib/components');
var elements = require('../lib/elements');
var users = require('../lib/users');
var utils = require('../lib/utils');

module.exports = function(app, nconf, db) {
app.get('/', function (req, res) {
app.get('/', function(req, res) {
if (req.session.email) {
delete req.session.sharedId;
res.render('index', {
Expand Down Expand Up @@ -83,7 +84,7 @@ module.exports = function(app, nconf, db) {
if (err) {
next(err);
} else if (!project) {
next(new Error('Project could not be found.'));
utils.render404(req, res);
} else {
req.project = project;

Expand All @@ -103,7 +104,7 @@ module.exports = function(app, nconf, db) {
if (err) {
next(err);
} else if (!screen) {
next(new Error('Screen could not be found.'));
utils.render404(req, res);
} else {
req.screen = screen;

Expand Down
6 changes: 5 additions & 1 deletion settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var utils = require('./lib/utils');

// Module dependencies.
module.exports = function(app, configurations, express) {
var clientSessions = require('client-sessions');
Expand Down Expand Up @@ -37,8 +39,10 @@ module.exports = function(app, configurations, express) {
}));

app.use(express.static(__dirname + '/public'));

app.use(app.router);

// last handler; assume 404 at this point
app.use(utils.render404);
});

app.configure('development, test', function(){
Expand Down
2 changes: 1 addition & 1 deletion todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
======================

- Validate action is an actual screen ID
- 404 page for invalid projectId/screenId/etc.
- Should auth be implemented for screen sharing page?
- Improve sharing page sidebar
- Add links on sharing page for visibility and return to prototype
Expand All @@ -29,3 +28,4 @@
/ Permissions for editing project + screen
/ Ensure project and screen exist to prototype screen page
/ Add validation for projectId and screenId paramters in route
/ 404 page for invalid projectId/screenId/etc.
7 changes: 7 additions & 0 deletions views/not-found.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extend layout

block sidebar
a.btn.btn-danger#back(href='/') ← Back to home

h2 Not Found
p The page you were looking for was not found. Please return to known territory by using your browser's back button or clicking the home link above.

0 comments on commit 3304d5e

Please sign in to comment.