Showing
1 changed file
with
12 additions
and
9 deletions
@@ -5,15 +5,22 @@ | @@ -5,15 +5,22 @@ | ||
5 | const headerModel = require('../models/header'); | 5 | const headerModel = require('../models/header'); |
6 | const logger = global.yoho.logger; | 6 | const logger = global.yoho.logger; |
7 | 7 | ||
8 | -exports.notFound = () => { | ||
9 | - return (req, res) => { | ||
10 | - res.status(404); | ||
11 | - | 8 | +const forceNoCache = (res) => { |
9 | + if (res) { | ||
12 | res.set({ | 10 | res.set({ |
13 | 'Cache-Control': 'no-cache', | 11 | 'Cache-Control': 'no-cache', |
14 | Pragma: 'no-cache', | 12 | Pragma: 'no-cache', |
15 | Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString() | 13 | Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString() |
16 | }); | 14 | }); |
15 | + } | ||
16 | +}; | ||
17 | + | ||
18 | + | ||
19 | +exports.notFound = () => { | ||
20 | + return (req, res) => { | ||
21 | + forceNoCache(res); | ||
22 | + | ||
23 | + res.status(404); | ||
17 | 24 | ||
18 | if (req.xhr) { | 25 | if (req.xhr) { |
19 | return res.json({ | 26 | return res.json({ |
@@ -40,11 +47,7 @@ exports.notFound = () => { | @@ -40,11 +47,7 @@ exports.notFound = () => { | ||
40 | */ | 47 | */ |
41 | exports.serverError = () => { | 48 | exports.serverError = () => { |
42 | return (err, req, res, next) => { | 49 | return (err, req, res, next) => { |
43 | - res.set({ | ||
44 | - 'Cache-Control': 'no-cache', | ||
45 | - Pragma: 'no-cache', | ||
46 | - Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString() | ||
47 | - }); | 50 | + forceNoCache(res); |
48 | 51 | ||
49 | logger.error(`error at path: ${req.url}`); | 52 | logger.error(`error at path: ${req.url}`); |
50 | logger.error(err); | 53 | logger.error(err); |
-
Please register or login to post a comment