mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 18:34:39 +03:00
cdc98dce15
closes #6368 - Add test to recreate the error in the static theme middleware. - Updated static theme middleware to not error if missing theme folder.
34 lines
903 B
JavaScript
34 lines
903 B
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 _.contains(blackListedFileTypes, ext);
|
|
}
|
|
|
|
function forwardToExpressStatic(req, res, next) {
|
|
if (!req.app.get('activeTheme')) {
|
|
next();
|
|
} else {
|
|
express.static(
|
|
path.join(config.paths.themePath, req.app.get('activeTheme')),
|
|
{maxAge: utils.ONE_YEAR_MS}
|
|
)(req, res, next);
|
|
}
|
|
}
|
|
|
|
function staticTheme() {
|
|
return function blackListStatic(req, res, next) {
|
|
if (isBlackListedFileType(req.url)) {
|
|
return next();
|
|
}
|
|
return forwardToExpressStatic(req, res, next);
|
|
};
|
|
}
|
|
|
|
module.exports = staticTheme;
|