mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-17 05:21:36 +03:00
f3d16352b1
refs #7488 - remove all ugly env checks - rather use config properties - replace process.env.NODE_ENV by config.get('env')
39 lines
1.1 KiB
JavaScript
39 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.getContentPath('themes'), req.app.get('activeTheme')),
|
|
{maxAge: config.get('caching:theme: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;
|