-
-
Notifications
You must be signed in to change notification settings - Fork 383
/
routes.js
41 lines (34 loc) · 735 Bytes
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
/**
* Module dependencies.
*/
const home = require('../app/controllers/home');
/**
* Expose
*/
module.exports = function(app) {
app.get('/', home.index);
/**
* Error handling
*/
app.use(function(err, req, res, next) {
// treat as 404
if (
err.message &&
(~err.message.indexOf('not found') ||
~err.message.indexOf('Cast to ObjectId failed'))
) {
return next();
}
console.error(err.stack);
// error page
res.status(500).render('500', { error: err.stack });
});
// assume 404 since no middleware responded
app.use(function(req, res) {
res.status(404).render('404', {
url: req.originalUrl,
error: 'Not found'
});
});
};