Last active
February 23, 2016 10:25
-
-
Save zerko/be995e01a33e15680749 to your computer and use it in GitHub Desktop.
This file contains 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
const Hapi = require('hapi'); | |
const server = new Hapi.Server(); | |
server.connection({port: 3000}); | |
server.register(require('vision'), (err) => { | |
if (err) { | |
throw err; | |
} | |
server.views({ | |
engines: { jade: require('jade') }, | |
path: __dirname, | |
compileOptions: { | |
pretty: true | |
} | |
}); | |
}); | |
server.route({ | |
method: 'GET', | |
path: '/', | |
handler: function(requst, reply) { | |
throw new Error; | |
} | |
}) | |
server.ext('onPreResponse', function (request, reply) { | |
if (request.response.isBoom) { | |
return reply.view('template', { | |
message: 'Boom!' | |
}) | |
} | |
reply.continue(); | |
}) | |
server.ext('onPreResponse', function (request, reply) { | |
console.log("I am never called"); | |
// do something with template context | |
request.response.source.context.message2 = 'Everything is fine'; | |
reply.continue(); | |
}) | |
server.start((err) => { | |
if (err) { | |
throw err; | |
} | |
console.log('Server running at:', server.info.uri); | |
}) |
This file contains 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
{ | |
"name": "hapi-onpreresponse-issue", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"dependencies": { | |
"hapi": "^13.0.0", | |
"jade": "^1.11.0", | |
"vision": "^4.0.1" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC" | |
} |
This file contains 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
div Message: #{message} | |
div Message2: #{message2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment