mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 01:40:21 +03:00
df7e64fafa
refs #10790 - Moved /core/apps into core/frontend - Moved /core/server/helpers to /core/frontend/helpers along with /core/server/services/themes - Changed helper location in overrides - Moved /core/server/services/routing to /core/frontend/services - Moved /core/server/services/url to /core/frontend/services - Moved /core/server/data/meta to /core/frontend/meta - Moved /core/server/services/rss to /core/frontend/services - Moved /core/server/data/xml to /core/frontend/services
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const config = require('../../../config');
|
|
const constants = require('../../../lib/constants');
|
|
const themeUtils = require('../../../../frontend/services/themes');
|
|
|
|
function isBlackListedFileType(file) {
|
|
const blackListedFileTypes = ['.hbs', '.md', '.json'];
|
|
const ext = path.extname(file);
|
|
|
|
return blackListedFileTypes.includes(ext);
|
|
}
|
|
|
|
function isWhiteListedFile(file) {
|
|
const whiteListedFiles = ['manifest.json'];
|
|
const base = path.basename(file);
|
|
|
|
return whiteListedFiles.includes(base);
|
|
}
|
|
|
|
function forwardToExpressStatic(req, res, next) {
|
|
if (!themeUtils.getActive()) {
|
|
return next();
|
|
}
|
|
|
|
const configMaxAge = config.get('caching:theme:maxAge');
|
|
|
|
express.static(themeUtils.getActive().path,
|
|
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : constants.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;
|