19 lines
444 B
JavaScript
19 lines
444 B
JavaScript
const ejs = require('ejs');
|
|
const path = require('path');
|
|
|
|
function renderPage(routePath, res, options = {}, fragment = false) {
|
|
ejs.renderFile(path.join(process.cwd(), 'views', routePath), options, (err, str) => {
|
|
if (err) {
|
|
return res.status(500).send(err.message);
|
|
}
|
|
|
|
if (fragment) {
|
|
res.send(str);
|
|
} else {
|
|
res.render('layout', { body: str, ...options });
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = renderPage;
|