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);
|
|
|
|
return _.contains(blackListedFileTypes, ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
function forwardToExpressStatic(req, res, next) {
|
2015-10-12 19:54:15 +03:00
|
|
|
express.static(
|
2015-09-28 13:22:55 +03:00
|
|
|
path.join(config.paths.themePath, req.app.get('activeTheme')),
|
|
|
|
{maxAge: utils.ONE_YEAR_MS}
|
|
|
|
)(req, res, next);
|
2015-07-15 19:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function staticTheme() {
|
|
|
|
return function blackListStatic(req, res, next) {
|
|
|
|
if (isBlackListedFileType(req.url)) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
return forwardToExpressStatic(req, res, next);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = staticTheme;
|