50 lines
846 B
JavaScript
Raw Normal View History

'use strict';
/**
* Module dependencies
*/
// Native
const path = require('path');
// Externals
const co = require('co');
const render = require('koa-ejs');
/**
* EJS hook
*/
2019-08-14 14:15:45 +02:00
module.exports = function(strapi) {
const hook = {
/**
* Default options
*/
2016-12-20 20:42:52 +01:00
defaults: {
root: path.join(strapi.config.appPath, strapi.config.paths.views),
layout: 'layout',
viewExt: 'ejs',
cache: true,
2019-08-14 14:15:45 +02:00
debug: true,
2016-12-20 20:42:52 +01:00
},
/**
* Initialize the hook
*/
2019-08-14 14:15:45 +02:00
initialize: () => {
2017-01-15 17:52:20 +01:00
// Force cache mode in production
if (strapi.config.environment === 'production') {
strapi.config.hook.settings.ejs.cache = true;
2017-01-15 17:52:20 +01:00
}
2017-07-26 18:53:48 +02:00
render(strapi.app, strapi.config.hook.settings.ejs);
strapi.app.context.render = co.wrap(strapi.app.context.render);
2019-08-14 14:15:45 +02:00
},
};
return hook;
};