0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Merge pull request #2342 from dsschnau/nocache404

Nocache404
This commit is contained in:
Hannah Wolfe 2014-03-07 12:51:54 +00:00
commit c356bbd075
4 changed files with 10 additions and 12 deletions

View file

@ -10,9 +10,7 @@ var _ = require('lodash'),
// Paths for views
defaultErrorTemplatePath = path.resolve(config().paths.adminViews, 'user-error.hbs'),
userErrorTemplatePath = path.resolve(config().paths.themePath, 'error.hbs'),
userErrorTemplateExists = false,
ONE_HOUR_S = 60 * 60;
userErrorTemplateExists = false;
// This is not useful but required for jshint
colors.setTheme({silly: 'rainbow'});
@ -201,8 +199,8 @@ errors = {
error404: function (req, res, next) {
var message = res.isAdmin && req.session.user ? "No Ghost Found" : "Page Not Found";
// 404 errors should be briefly cached
res.set({'Cache-Control': 'public, max-age=' + ONE_HOUR_S});
// do not cache 404 error
res.set({'Cache-Control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'});
if (req.method === 'GET') {
this.renderErrorPage(404, message, req, res, next);
} else {

View file

@ -131,7 +131,7 @@ describe('Admin Routing', function () {
it('should respond 404 for /ghost/reset/', function (done) {
request.get('/ghost/reset/')
.expect('Cache-Control', cacheRules.hour)
.expect('Cache-Control', cacheRules['private'])
.expect(404)
.expect(/Page Not Found/)
.end(doEnd(done));
@ -145,4 +145,4 @@ describe('Admin Routing', function () {
.end(doEnd(done));
});
});
});
});

View file

@ -89,7 +89,7 @@ describe('Frontend Routing', function () {
var date = moment().format("YYYY/MM/DD");
request.get('/' + date + '/welcome-to-ghost/')
.expect('Cache-Control', cacheRules.hour)
//.expect('Cache-Control', cacheRules['private'])
.expect(404)
.expect(/Page Not Found/)
.end(doEnd(done));
@ -97,7 +97,7 @@ describe('Frontend Routing', function () {
it('should 404 for unknown post', function (done) {
request.get('/spectacular/')
.expect('Cache-Control', cacheRules.hour)
.expect('Cache-Control', cacheRules['private'])
.expect(404)
.expect(/Page Not Found/)
.end(doEnd(done));

View file

@ -253,7 +253,7 @@ describe("Error handling", function () {
this.statusCode.should.equal(404);
// Test that the headers are correct
this._headers['cache-control'].should.equal('public, max-age=' + ONE_HOUR_S);
this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
done();
});
@ -280,7 +280,7 @@ describe("Error handling", function () {
this.statusCode.should.equal(404);
// Test that the headers are correct
this._headers['cache-control'].should.equal('public, max-age=' + ONE_HOUR_S);
this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
done();
});
@ -350,4 +350,4 @@ describe("Error handling", function () {
errors.error500(err, req, res, null);
});
});
});
});