Ghost/core/server/web/middleware/cache-control.js
Katharina Irrgang 7bcccc71dc
Moved apps into web folder (#9308)
refs #9178

- move express apps to one place (called `web`)
- requires https://github.com/TryGhost/Ghost-Admin/pull/923
- any further improvements are not part of this PR
- this PR just moves the files and ensures the paths are up-to-date
2017-12-06 17:37:54 +01:00

37 lines
1.0 KiB
JavaScript

// # CacheControl Middleware
// Usage: cacheControl(profile), where profile is one of 'public' or 'private'
// After: checkIsPrivate
// Before: routes
// App: Admin|Site|API
//
// Allows each app to declare its own default caching rules
var _ = require('lodash'),
config = require('../../config'),
cacheControl;
cacheControl = function cacheControl(options) {
var profiles = {
public: 'public, max-age=' + config.get('caching:frontend:maxAge'),
private: 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
},
output;
if (_.isString(options) && profiles.hasOwnProperty(options)) {
output = profiles[options];
}
return function cacheControlHeaders(req, res, next) {
if (output) {
if (res.isPrivateBlog) {
res.set({'Cache-Control': profiles.private});
} else {
res.set({'Cache-Control': output});
}
}
next();
};
};
module.exports = cacheControl;