diff --git a/modules/core/client/config/core.client.routes.js b/modules/core/client/config/core.client.routes.js index 7328d0d2..fe5692bd 100644 --- a/modules/core/client/config/core.client.routes.js +++ b/modules/core/client/config/core.client.routes.js @@ -3,14 +3,19 @@ // Setting up route angular.module('core').config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { - // Redirect to home view when route not found - $urlRouterProvider.otherwise('/'); + + // Redirect to 404 when route not found + $urlRouterProvider.otherwise('not-found'); // Home state routing $stateProvider. - state('home', { - url: '/', - templateUrl: 'modules/core/views/home.client.view.html' - }); + state('home', { + url: '/', + templateUrl: 'modules/core/views/home.client.view.html' + }). + state('not-found', { + url: '/not-found', + templateUrl: 'modules/core/views/404.client.view.html' + }); } ]); diff --git a/modules/core/client/views/404.client.view.html b/modules/core/client/views/404.client.view.html new file mode 100644 index 00000000..6e79d29f --- /dev/null +++ b/modules/core/client/views/404.client.view.html @@ -0,0 +1,6 @@ +

Page Not Found

+ diff --git a/modules/core/server/controllers/core.server.controller.js b/modules/core/server/controllers/core.server.controller.js index 3b427c38..efda2451 100644 --- a/modules/core/server/controllers/core.server.controller.js +++ b/modules/core/server/controllers/core.server.controller.js @@ -1,7 +1,7 @@ 'use strict'; /** - * Render the main applicaion page + * Render the main application page */ exports.renderIndex = function(req, res) { res.render('modules/core/server/views/index', { @@ -19,10 +19,25 @@ exports.renderServerError = function(req, res) { }; /** - * Render the server not found page + * Render the server not found responses */ exports.renderNotFound = function(req, res) { - res.status(404).render('modules/core/server/views/404', { - url: req.originalUrl - }); + res.status(404); + + // Respond with html page + if (req.accepts('html')) { + res.render('modules/core/server/views/404', { + url: req.originalUrl + }); + return; + } + + // Respond with json to API calls + if (req.accepts('json')) { + res.json({ error: 'Path not found' }); + return; + } + + // Default to plain-text + res.type('txt').send('Path not found'); }; diff --git a/modules/core/server/views/404.server.view.html b/modules/core/server/views/404.server.view.html index 40407617..94e37192 100644 --- a/modules/core/server/views/404.server.view.html +++ b/modules/core/server/views/404.server.view.html @@ -2,7 +2,9 @@ {% block content %}

Page Not Found

-
+
+ {% endblock %}