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

enabling pagination only on route config level #19

Open
lostdalek opened this issue Oct 5, 2016 · 4 comments
Open

enabling pagination only on route config level #19

lostdalek opened this issue Oct 5, 2016 · 4 comments

Comments

@lostdalek
Copy link
Contributor

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 lostdalek changed the title enable pagination only on route configuration enable pagination only on route config level Oct 5, 2016
@lostdalek lostdalek changed the title enable pagination only on route config level enabling pagination only on route config level Oct 5, 2016
@lostdalek
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@fknop
Copy link
Owner

fknop commented Oct 5, 2016

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
Copy link
Contributor Author

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

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

No branches or pull requests

2 participants