Git Product home page Git Product logo

hapi-qs's People

Contributors

dafortune avatar hbernaciak avatar rajivm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hapi-qs's Issues

Doesn't work with hapi v18

Release notes: hapijs/hapi#3871

look for request.setUrl() references in your code and ensure you are only passing valid arguments.
if you use request.setUrl() to override query processing (e.g. using the qs module), consider switching to the much simpler server.options.query.parser option.

I assume this package can be deprecated and alternatively the change to the query parser suggested?

The v18 way would be:

query: {
  parser: (query) => qs.parse(query)
}

Wrong payload

The payload is set to an object but it should be empty. That causes an error in hapijs/h2o2. To reproduce, here is the minimal setup.

package.json

{
  "name": "hapi-h2o2-error",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "good": "^7.0.1",
    "good-console": "^6.1.2",
    "good-squeeze": "^4.0.0",
    "h2o2": "^5.1.0",
    "hapi": "^13.5.0",
    "hapi-qs": "^1.1.1"
  }
}

The index.js:

var Hapi = require('hapi');
var server = new Hapi.Server();

server.connection({host: 'localhost', port: 3000});

server.register([
  require('h2o2'),
  require('hapi-qs'),
  {
    register: require('good'),
    options: {
      reporters: {
        console: [{
          module: 'good-squeeze',
          name: 'Squeeze',
          args: [{log: '*', response: '*'}]
        }, {
          module: 'good-console'
        }, 'stdout']
      }
    }
  }
], (error) => {
  if (error) {
    throw error;
  }

  server.route([  {
    method: 'GET',
    path: '/test',
    handler: {
      proxy: {
        passThrough: true,
        mapUri: (request, callback) => {
          callback(null, 'https://api.github.com/users/ro-ka');
        }
      }
    }
  }]);
});

server.start(error => {
  if (error) {
    throw(error);
  }

  server.log('info', `Server running at: ${server.info.uri}`);
});

I installed good for logging. What causes this error is this header: Content-Type: application/x-www-form-urlencoded. So when using curl, this is what happens:

~ – curl 'http://localhost:3000/test' -H 'Content-Type: application/x-www-form-urlencoded'
{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"}

~ – curl 'http://localhost:3000/test'
{
  "login": "ro-ka",
  "id": 840022,
  "avatar_url": "https://avatars.githubusercontent.com/u/840022?v=3",
  "gravatar_id": "",
  "url": "https://api.github.com/users/ro-ka",
  …
}

The error only occurs when the header set. The payload is an empty object which breaks the proxy plugin. Can the payload be set to null or an empty string when there is nothing parsed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.