8000 Add rubberduck args to service events parameters by loris · Pull Request #148 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content

Add rubberduck args to service events parameters#148

Merged
daffl merged 6 commits intofeathersjs:masterfeathersjs/feathers:masterfrom
loris:master
Oct 25, 2015
Merged

Add rubberduck args to service events parameters#148
daffl merged 6 commits intofeathersjs:masterfrom
loris:master

Conversation

@loris
Copy link
Contributor
@loris loris commented Oct 3, 2015

Update the event mixins to pass along the ruberduck args parameter.
It allows access to contextual data (such as data attached to req.feathers) in event listeners, and makes it consistent with hooks.

I know about backward incompatibility, so maybe for the next major release.

@daffl
Copy link
Member
daffl commented Oct 3, 2015

Nice! This is a new features but it doesn't look like it is breaks compatibility. The first parameter is still the data so it shouldn't break any existing listeners.

I'm wondering if the second parameters should look the same as a feathers-hooks after hook object though.

@daffl
Copy link
Member
daffl commented Oct 3, 2015

For that to happen we might have to move https://github.com/feathersjs/feathers-hooks/blob/master/lib/utils.js#L42 into feathers-commons so that it can be shared.

@loris
Copy link
Contributor Author
loris commented Oct 4, 2015

That would be great to make the parameter consistent with the hook one, I didn’t know about that codebase already existing. Moving it to feathers-commons looks like a good idea.

@daffl
Copy link
Member
daffl commented Oct 6, 2015

I just made a 0.2.8 release of feathers-commons which should support getting the hookObject. You should be able to do:

var hookObject = require('feathers-commons').hooks.hookObject;
var hook = hookObject(method, 'after', args);

Can you try it and update the PR if it works?

@loris
Copy link
Contributor Author
loris commented Oct 6, 2015

It works like a charm! Thanks

@daffl
Copy link
Member
daffl commented Oct 6, 2015

Perfect. Are you going to use those locally or via websockets? I think it's fine on the server but I'm wondering if also sending the hookObject through websockets might pose a security risk (e.g. you might not want to send things like params.user or anything else attached to params).

@loris
Copy link
Contributor Author
loris commented Oct 6, 2015

Right now, i’m not using websocket at all in my projects using feathers, but that will come. I will filter out sensitive data. But right now, my use case is mainly to attach contextual data like ip, userAgent, referrer, etc, and then use feather services event dispatcher to fetch those events and to several stuff with them (like storing them in DB, calling webhook, outputing to console, etc.) where contextual data is important.

@daffl
Copy link
Member
daffl commented Oct 15, 2015

I didn't forget about this! I think the PR can be merged but I should probably update feathers-commons to not send additional parameters through the socket since - as you mentioned - you can accidentally transmit very sensitive information (also, bandwidth).

Side-note about scaling: If you want to use feathers-sync to scale your application to multiple instances and still make sure that all connected clients get all real-time events you might run into issues when handling events on the server. For example, if you scale your app to three instances (e.g. three Heroku dynos) and you are listening to an event which sends out an email, all three instances will send out that email. This is when hooks are the better choice since a hook will only run on the instance that handles the request.

@daffl daffl added this to the 1.2.0 milestone Oct 22, 2015
@daffl
Copy link
Member
daffl commented Oct 23, 2015

It looks like this is handled already in feathers-commons which only dispatches the data to sockets. I think we can get this and #151 in for a 1.2

daffl added a commit that referenced this pull request Oct 25, 2015
Add rubberduck args to service events parameters
@daffl daffl merged commit 3931807 into feathersjs:master Oct 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0