mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
faea2da596
- we're slowly trying to draw the lines between the backend and the frontend correctly - these files deal only with serving the frontend so they should live there - there are lots of mixed requires in these files, so having them in the right place makes that clear
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const path = require('path');
|
|
const config = require('../../../shared/config');
|
|
const constants = require('@tryghost/constants');
|
|
const themeEngine = require('../../services/theme-engine');
|
|
const express = require('../../../shared/express');
|
|
|
|
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 (!themeEngine.getActive()) {
|
|
return next();
|
|
}
|
|
|
|
const configMaxAge = config.get('caching:theme:maxAge');
|
|
|
|
express.static(themeEngine.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;
|