-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (22 loc) · 780 Bytes
/
Copy pathindex.js
File metadata and controls
25 lines (22 loc) · 780 Bytes
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
'use strict';
function buildPath(statusCode) {
var path = require('path');
var serverErrorPagesPath = path.join(require('server-error-pages').path, '_site');
return path.join(serverErrorPagesPath, statusCode + '-error.html');
}
function isAvailableStatusCode(statusCode) {
return ([403, 404, 500, 502, 503, 504].indexOf(statusCode) > -1);
}
module.exports = [
function (req, res, next) {
res.statusCode = 404;
return res.sendFile(buildPath(404));
},
function (err, req, res, next) {
res.statusCode = err.status || err.statusCode || res.status || res.statusCode;
if (!isAvailableStatusCode(res.statusCode)) {
res.statusCode = 500;
}
return res.sendFile(buildPath(res.statusCode));
}
];