fknop / hapi-pagination

Hapi plugin to handle "custom" pagination
MIT License
63 stars 35 forks source link

enabling pagination only on route config level #19

Open lostdalek opened 7 years ago

lostdalek commented 7 years ago

Hi, not sure if there is a bug or I can't get the configuration right but I would like to disable pagination by default and only enable it on specific route.

this is what i'm trying: plugin registration (with glue)

registrations: [
        {
            plugin: {
                register: 'hapi-pagination',
                pagination: {
                    enabled: false
                }
            }, ...

and enabling it on specific route (it's working great):

method: 'GET',
path: '/paginatedResource',
config: {
plugins: {
                pagination: {
                    enabled: true,
                    limit: this.paginationLimit
                },
            }
},
handler: ...

but on a route without plugins.pagination configured, I have the following error:

server-0 | Debug: internal, implementation, error server-0 | Error: Uncaught error: The results must be an array server-0 | at Object.exports.assert (xxxxx/node_modules/hoek/lib/index.js:736:11)

manually setting pagination.enabled = false in the route config is working, but I don't want to explicitly disable on route level and I don't want to maintain a global exclude or include route array in the plugin configuration. I only want to enable when I need on route configuration level

I'm I doing something wrong? thanks!

lostdalek commented 7 years ago

I've found a workaround, default configuration is having routes: { include: ['*'], exclude: [] } It just need to remove the * in order to disable the pagination globally

here is my plugin configuration:

plugin: {
                register: 'hapi-pagination',
                pagination: {
                    enabled: false
                },
                options: {
                 routes: { include: [], exclude: [] } 
                }
            }
lostdalek commented 7 years ago

I let the issue open, I think that enabled: false should really disable the plugin without throwing an error :)

fknop commented 7 years ago

Hi,

I'm having Internet issues at the moment I won't be able to look at it right now. If you think you've found a way to solve your issue, I would be happy to accept a PR !

lostdalek commented 7 years ago

Hi, I don't have the time to dig in the source code at the moment so I provided an example, might be usefull for somebody :)