Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Using Plugin in Routes #2

Open
zizzle6717 opened this issue Dec 30, 2016 · 1 comment
Open

Using Plugin in Routes #2

zizzle6717 opened this issue Dec 30, 2016 · 1 comment

Comments

@zizzle6717
Copy link

zizzle6717 commented Dec 30, 2016

This would be a phenomenal package if I could figure out how to get it working.

I tried this...
let db = request.plugins["hapi-massive"].db;

...and the error tells me that request is undefined...So, if I try the same thing within the request handler, the error says...'Cannot ready property "db" of undefined'

I'm fairly new to plugins, especially custom plugins, and I feel like I'm missing something obvious.

@zizzle6717
Copy link
Author

zizzle6717 commented Dec 30, 2016

I was able to resolve this by writing a request handler like so...

get: function(request, reply) {
    let db = request.server.plugins['hapi-massive'].db;
    db.Contacts.findAsync(request.params.id).then((contact) => {
        if (contact) {
            reply(contact).code(200);
        } else {
	    reply().code(404);
        }
    });
}

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

No branches or pull requests

1 participant