Ghost/core/server/middleware/static-theme.js
kirrg001 0ae0a0b490 🎨 change how we get and set config
refs #6982
- a replace for all config usages
- always use config.get or config.set
- this a pure replacement, no logic has changed

[ci skip]
2016-09-20 15:59:34 +01:00

40 lines
1.1 KiB
JavaScript

var _ = require('lodash'),
express = require('express'),
path = require('path'),
config = require('../config'),
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 (!req.app.get('activeTheme')) {
next();
} else {
express.static(
path.join(config.get('paths').themePath, req.app.get('activeTheme')),
{maxAge: 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;