Hapi: Cannot proxy if payload is parsed or if output is not stream or data

Created on 16 Jul 2015  路  4Comments  路  Source: hapijs/hapi

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)
})
documentation

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:

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
    }
  }
})

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeremiahlee picture jeremiahlee  路  4Comments

foobar1123 picture foobar1123  路  3Comments

midknight41 picture midknight41  路  4Comments

RohovDmytro picture RohovDmytro  路  4Comments

shamsher31 picture shamsher31  路  5Comments