If you follow the example in the documentation, it does not work, it complain with:
Error: Uncaught error: Cannot proxy if payload is parsed or if output is not stream or data
How can that be? It should work like this!
http://hapijs.com/api#replyproxyoptions
var Hapi = require('hapi')
var server = new Hapi.Server()
server.connection({
port: '9500'
})
server.route({
method: '*',
path: '/',
handler: function(request, reply) {
return reply.proxy({ host: 'example.com', port: 80, protocol: 'http' });
}
})
server.start(function() {
console.log('Server running at:', server.info.uri)
})
I'm having the same issue with something I'm working on. Might be an opportunity for me to contribute to Hapi :)
Found the solution, it was difficult figuring out as a starter hapi.js user. You had to have payload: false, like this:
server.route({
method: '*',
path: '/{p*}',
config: {
handler: function(request, reply) {
return reply.proxy({ host: 'example.com', port: 80, protocol: 'http' })
},
payload: {
output: 'stream',
parse: false
}
}
})
@kevinsimper had a similar issue myself a little bit ago a cool thing with hapi is its composed of small modules and so if you looked into the h2o2 and start with L56 and then L70 that would point you in the right direction thats what i do if i cant find it in the docs but documentation would be the great path as well. :smile:
@osukaa Can you see if we can make the proxy documentation clearer? I am closing this issue since h2o2 is no longer part of core.
Most helpful comment
Found the solution, it was difficult figuring out as a starter hapi.js user. You had to have payload: false, like this: