Support for Hapi.js?
See original GitHub issueI’m getting an error when trying to use Nunjucks with Hapi.js.
Steps to reproduce:
-
npm i hapi nunjucks -S
-
Create a server.js file with the following contents:
'use strict'; var Hapi = require('hapi'); var nunjucks = require('nunjucks'); // var handlebars = require('handlebars'); var serverOptions = { views: { engines: { html: nunjucks }, path: 'views' } }; var server = new Hapi.Server(3000, serverOptions); server.route({ method: 'GET', path: '/', handler: function (res, reply) { reply.view('index', { title: 'Nice site', name: 'Roger', header: 'HEADERR', footer: 'FOOTERR' }); } }); server.start(function () { console.log('Hapi %s server running at %s', Hapi.version, server.info.uri); });
-
Create a views/index.html with the following contents:
<!doctype html> <html lang="en"> <head> <title>{{ title }}</title> </head> <body> <div class="container"> {{ header }} <header class="page-header"> <h1>Hello {{ name }}, <small>Welcome back</small></h1> </header> {{ footer }} </div> </body> </html>
-
$ npm start
-
$ open http://localhost:3000
Actual results
$ node server
Hapi 6.9.0 server running at http://pdehaan.local:3000
Debug: hapi, internal, implementation, error
TypeError: object is not a function: object is not a function
at renderer (/Users/pdehaan/dev/github/hapi-examples/hapi-views-nunjucks/node_modules/hapi/node_modules/vision/lib/index.js:145:36)
at /Users/pdehaan/dev/github/hapi-examples/hapi-views-nunjucks/node_modules/hapi/node_modules/vision/lib/index.js:294:13
at /Users/pdehaan/dev/github/hapi-examples/hapi-views-nunjucks/node_modules/hapi/node_modules/vision/lib/index.js:411:20
at Object.engine.compileFunc (/Users/pdehaan/dev/github/hapi-examples/hapi-views-nunjucks/node_modules/hapi/node_modules/vision/lib/index.js:154:24)
at /Users/pdehaan/dev/github/hapi-examples/hapi-views-nunjucks/node_modules/hapi/node_modules/vision/lib/index.js:401:16
at fs.js:271:14
at Object.oncomplete (fs.js:107:15)
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Help - hapi.dev
Free support is always available on GitHub. Just open an issue with your question and a community member will try to help. For...
Read more >hapi.dev - The simple, secure framework developers trust
hapi provides the right set of core APIs and extensible plugins to support the requirements of a modern service - session management, security,...
Read more >hapi modules LTS support policy
The hapi core module and its dependencies are published under the following support rules: Every major version of the core module receives at...
Read more >Plugins - hapi.dev
Plugins. There are dozens of plugins for hapi, ranging from documentation to authentication, and much more. If you wrote or use a plugin...
Read more >Resources - hapi.dev
This handbook is a collection of tutorials for Hapi.js framework. You can find tutorials about validation, working with 3rd plugins, sending/getting data, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ran into this myself. The Nunjucks.compile() method does not export the handlebars-style interface expected by Hapi, but it can be trivially replicated using a combination of Nunjucks’ compile() and render() so I wrote a teeny-tiny module to do it:
https://www.npmjs.org/package/nunjucks-hapi
The following example works:
Hey Paulo - Glad you could get it working, could you tell me what about my module isn’t working for you? I double checked and added inheritance and includes to my example:
https://github.com/seldo/nunjucks-hapi/tree/master/test
And it seems to be working fine. [Edit: I had trouble getting your solution to work initially, deleted that.]
Your solution works too.