add 404
This commit is contained in:
parent
b53237daca
commit
12f0f4bee6
22
index.js
22
index.js
|
@ -21,15 +21,6 @@ let RedisStore = require("connect-redis")(session)
|
||||||
|
|
||||||
const { APP_PORT, APP_KEY } = process.env;
|
const { APP_PORT, APP_KEY } = process.env;
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
|
||||||
req.start = Date.now();
|
|
||||||
res.on('header', (res) => {
|
|
||||||
let time = Date.now() - req.start;
|
|
||||||
console.log(time)
|
|
||||||
res.setHeader('X-Reponse-Time', time);
|
|
||||||
})
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
app.use(bodyparser.json());
|
app.use(bodyparser.json());
|
||||||
app.use(bodyparser.urlencoded({ extended: true }));
|
app.use(bodyparser.urlencoded({ extended: true }));
|
||||||
app.use(cookie_parse(APP_KEY))
|
app.use(cookie_parse(APP_KEY))
|
||||||
|
@ -47,8 +38,17 @@ app.use(require('./routes'));
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
|
|
||||||
// 404
|
// 404
|
||||||
app.use((req, res, next) => {
|
app.use(async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
if (res.headersSent) return next();
|
||||||
|
const Helpers = require('./helpers');
|
||||||
|
res.status(404).send(await Helpers.ViewLoader.load('error.pug', {
|
||||||
|
error: '404 Not Found',
|
||||||
|
message: 'The requested page was not found.'
|
||||||
|
}))
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue