Ghost/core/server/web/middleware/static-theme.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

42 lines
1.2 KiB
JavaScript

var _ = require('lodash'),
express = require('express'),
path = require('path'),
config = require('../../config'),
themeUtils = require('../../themes'),
utils = require('../../utils');
function isBlackListedFileType(file) {
var blackListedFileTypes = ['.hbs', '.md', '.json'],
ext = path.extname(file);
return _.includes(blackListedFileTypes, ext);
}
function isWhiteListedFile(file) {
var whiteListedFiles = ['manifest.json'],
base = path.basename(file);
return _.includes(whiteListedFiles, base);
}
function forwardToExpressStatic(req, res, next) {
if (!themeUtils.getActive()) {
return next();
}
var configMaxAge = config.get('caching:theme:maxAge');
express.static(themeUtils.getActive().path,
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : utils.ONE_YEAR_MS}
)(req, res, next);
}
function staticTheme() {
return function blackListStatic(req, res, next) {
if (!isWhiteListedFile(req.path) && isBlackListedFileType(req.path)) {
return next();
}
return forwardToExpressStatic(req, res, next);
};
}
module.exports = staticTheme;