add some checks to templatesOnDemand

This commit is contained in:
Barış Soner Uşaklı
2018-02-14 16:29:33 -05:00
parent dcc896ee05
commit 575b70b5ab

View File

@@ -237,12 +237,18 @@ middleware.templatesOnDemand = function (req, res, next) {
fs.readFile(filePath.replace(/\.js$/, '.tpl'), 'utf8', cb); fs.readFile(filePath.replace(/\.js$/, '.tpl'), 'utf8', cb);
}, },
function (source, cb) { function (source, cb) {
if (!source) {
return cb(new Error('[[error:templatesOnDemand.source-template-empty]]'));
}
Benchpress.precompile({ Benchpress.precompile({
source: source, source: source,
minify: global.env !== 'development', minify: global.env !== 'development',
}, cb); }, cb);
}, },
function (compiled, cb) { function (compiled, cb) {
if (!compiled) {
return cb(new Error('[[error:templatesOnDemand.compiled-template-empty]]'));
}
fs.writeFile(filePath, compiled, cb); fs.writeFile(filePath, compiled, cb);
}, },
], function (err) { ], function (err) {