2015-07-15 19:01:23 +03:00
|
|
|
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);
|
2016-06-11 21:23:27 +03:00
|
|
|
return _.includes(blackListedFileTypes, ext);
|
2015-07-15 19:01:23 +03:00
|
|
|
}
|
|
|
|
|
2016-06-29 23:44:01 +03:00
|
|
|
function isWhiteListedFile(file) {
|
|
|
|
var whiteListedFiles = ['manifest.json'],
|
|
|
|
base = path.basename(file);
|
|
|
|
return _.includes(whiteListedFiles, base);
|
|
|
|
}
|
|
|
|
|
2015-07-15 19:01:23 +03:00
|
|
|
function forwardToExpressStatic(req, res, next) {
|
2016-01-23 23:34:11 +03:00
|
|
|
if (!req.app.get('activeTheme')) {
|
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
express.static(
|
2016-09-13 23:24:57 +03:00
|
|
|
path.join(config.getContentPath('themes'), req.app.get('activeTheme')),
|
2016-01-23 23:34:11 +03:00
|
|
|
{maxAge: utils.ONE_YEAR_MS}
|
|
|
|
)(req, res, next);
|
|
|
|
}
|
2015-07-15 19:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function staticTheme() {
|
|
|
|
return function blackListStatic(req, res, next) {
|
2016-06-29 23:44:01 +03:00
|
|
|
if (!isWhiteListedFile(req.path) && isBlackListedFileType(req.path)) {
|
2015-07-15 19:01:23 +03:00
|
|
|
return next();
|
|
|
|
}
|
|
|
|
return forwardToExpressStatic(req, res, next);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = staticTheme;
|