Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with hapi v18 #22

Open
mweibel opened this issue Jun 24, 2019 · 3 comments
Open

Doesn't work with hapi v18 #22

mweibel opened this issue Jun 24, 2019 · 3 comments

Comments

@mweibel
Copy link

mweibel commented Jun 24, 2019

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)
}
@dafortune
Copy link
Owner

Hey @mweibel thanks for the pointer and sorry about the delay, I had not time to look at this deeply today, but if the integration with QS in Hapi v18 is so easy I'd say that does not worth having this plugin anymore and so it worth deprecating it. Will look into it in the following weeks.

Thanks a lot.

@petermilan
Copy link

petermilan commented Nov 16, 2021

I think this module is still needed.

From https://hapi.dev/api?v=20.2.0#-serveroptionsqueryparser

the method must return an object where each key is a parameter and matching value is the parameter value. If the method throws, the error is used as the response or returned when request.setUrl() is called.

so it looks like hapi doeas not allow nested objects. It just allows format like this:

  'q[query][search][firstname]': 'John',
  'q[query][search][lastname]': 'Doe',

@petermilan
Copy link

this seems to work

    parser: (query) => {
      if (!query) {
        return query;
      }
      const parsedQuery = Object.entries(query).reduce((acc, [key, value]) => {
        _.set(acc, key, value);
        return acc;
      }, {});

      return parsedQuery;
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants