Created
February 26, 2016 22:55
-
-
Save kevboutin/be393570b044894ecfc7 to your computer and use it in GitHub Desktop.
Shows how to use view templating with hapi within node.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Hapi = require('hapi'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 8000 }); | |
// test by using this on browser: | |
// http://localhost:8000/kevin | |
server.register(require('vision'), () => { | |
server.views({ | |
engines: { | |
hbs: require('handlebars') | |
}, | |
relativeTo: __dirname, | |
layout: true, | |
path: 'views' | |
}); | |
server.route({ | |
method: 'GET', | |
path: '/{name?}', | |
handler: function(request, response) { | |
response.view('home', { name: request.params.name || 'World' }); | |
} | |
}); | |
server.start(() => console.log(`Started at ${server.info.uri}`)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment