ext in defaultConfig, "onPreHandler" must be an object #38

Closed
opened 2017-02-08 03:40:55 +00:00 by ds009 · 4 comments
ds009 commented 2017-02-08 03:40:55 +00:00 (Migrated from github.com)

Hello, I'm new to Hapi.js and its 'ext'
I have a problem with this plugin when adding default config with 'onPrehandler'
defaultConfig: { auth: false, ext: { onPreHandler: (request, reply)=>{ debug(request) request.query.limit=25; reply.continue(); } } },
the error is "onPreHandler" must be an object
How can I solve it?
I want requests to always have a limit, maybe there is a better way to do this?
Thanks

Hello, I'm new to Hapi.js and its 'ext' I have a problem with this plugin when adding default config with 'onPrehandler' `defaultConfig: { auth: false, ext: { onPreHandler: (request, reply)=>{ debug(request) request.query.limit=25; reply.continue(); } } }, ` the error is `"onPreHandler" must be an object` How can I solve it? I want requests to always have a limit, maybe there is a better way to do this? Thanks
mdibaiee commented 2017-02-08 06:05:39 +00:00 (Migrated from github.com)

@ds009 Hey, I personally am not sure about it as I didn't have to use it yet. 🤔

I found this example on their documentation though:

server.ext({
    type: 'onRequest',
    method: function (request, reply) {

        // Change all requests to '/test'
        request.setUrl('/test');
        return reply.continue();
    }
});

Maybe you should pass something like:

ext: [{
  type: 'onPreHander',
  method: (request, reply) => {...}
}]
@ds009 Hey, I personally am not sure about it as I didn't have to use it yet. 🤔 I found this example on their [documentation](https://hapijs.com/api#request-lifecycle) though: ```javascript server.ext({ type: 'onRequest', method: function (request, reply) { // Change all requests to '/test' request.setUrl('/test'); return reply.continue(); } }); ``` Maybe you should pass something like: ```javascript ext: [{ type: 'onPreHander', method: (request, reply) => {...} }] ```
ds009 commented 2017-02-08 14:38:46 +00:00 (Migrated from github.com)

@mdibaiee Thank you for your reply, I tried this way but it didn't work. I switched to another solution by not using 'ext'.

@mdibaiee Thank you for your reply, I tried this way but it didn't work. I switched to another solution by not using 'ext'.
mdibaiee commented 2017-02-08 14:40:05 +00:00 (Migrated from github.com)

@ds009 glad you got to fix your problem. Would you mind sharing your solution so others who might encounter it in the future could use your answer? Thanks 😁 👍

@ds009 glad you got to fix your problem. Would you mind sharing your solution so others who might encounter it in the future could use your answer? Thanks :grin: :+1:
ds009 commented 2017-02-13 02:07:39 +00:00 (Migrated from github.com)

@mdibaiee Sorry, I just wrote a part of routes myself without using this plugin, it's not an elegant solution worth to be shared...

@mdibaiee Sorry, I just wrote a part of routes myself without using this plugin, it's not an elegant solution worth to be shared...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: thereadme/hapi-sequelize-crud#38
No description provided.