Hapi.js dynamic template rendering using consolidate. hapi-consolidate adds two new methods to the server and reply interfaces of Hapi.js.
npm install --save hapi-consolidate
const Hapi = require("hapi");
const path = require("path");
const server = new Hapi.Server();
server.connection({port: 8080});
server.register(require("hapi-consolidate"), err => {
if (err) throw err;
server.consolidate({
name: "pug",
path: path.resolve(__dirname, 'views'),
extension: 'pug',
options: {
cache: true
}
});
});
server.route({
method: 'GET',
path: '/',
config: {
handler: (request, reply) => {
reply.render('index', {username: 'admin'});
}
}
});
server.start(err => {
if (err) throw err;
});