You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the documentation, The RethinkDB library and the connection are bound to the server context inside handlers on this.rethinkdb and this.rethinkdbConn.
However, I'm not being able to access those, only using request.server.plugins etc. Is it because the context set inside a plugin with server.bind() is only available inside the plugin itself ?
{
method: 'GET',
path: '/list-of-things',
handler: function(request, reply) {
// I have to use it like this:
const r = request.server.plugins['hapi-rethinkdb'].rethinkdb;
const connection = request.server.plugins['hapi-rethinkdb'].connection;
// Because this throws undefined:
const r = this.rethinkdb;
const connection = this.rethinkdbConn
}
}
Thank you.
The text was updated successfully, but these errors were encountered:
It's really weird; I was checking this (long time without seeing the code) and on index.js L37-40 is making the bind correctly as defined in the documentation :-/
I was checking the documentation here and it says that
When setting context inside a plugin, the context is applied only to methods set up by the plugin.
Maybe that's why. I'm very new to Hapi js so I don't know much about how plugins work, but perhaps there's a way to bind the library and connect with a shorter syntax. I mean, it's also fine as it is now but it's a bit verbose to make reference to rethinkdb and connection like I mentioned.
You can always import all this to a single file, and make it so that file exports them. Remember when you make an assignation on javascript is just a reference and it's cached because of node, so:
According to the documentation, The RethinkDB library and the connection are bound to the server context inside handlers on
this.rethinkdb
andthis.rethinkdbConn
.However, I'm not being able to access those, only using request.server.plugins etc. Is it because the context set inside a plugin with
server.bind()
is only available inside the plugin itself ?My code is like this:
index.js
routes.js:
Thank you.
The text was updated successfully, but these errors were encountered: