-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
onSend hook not being called on web socket route #203
Comments
The documentation is incorrect and |
Hello, can i try to fix this issue?? |
@Ekott2006 I don't think it really makes sense to call the |
I guess, we would need to implement a new "hook" stage like calling it "onWebsocketSend". And then handle the "hooks" before calling the webhook handler here. Line 141 in ec0e7ae
|
So, what's next?? |
@Ekott2006 @michele-tonizzo what did you want the |
@airhorns In my case I had to apply a mask to the reply after it was sent out of the route. For example users that can read other users shipping addresses but not their billing addresses. They had a permission mask There surely are alternatives to solve my problem, for example I could do everything inside the route and get the users permissions and filter the data But I wanted something that could be written inside a plugin in order to have a cleaner code (at the cost of speed, selecting when querying the db is much better move). The plugin would get the mask based on the user permissions and filter out the data automatically. |
@michele-tonizzo is the reply you were sending a websocket message or a normal JSON reply? |
It was a JSON serialised into a string and sent as websocket message |
Ah, ok. And I take it you were expecting the |
Yes exactly |
I think that |
The onSend hook is not called because it is not part of the lifecycle of the websocket connection. Thats why I proposed to expose the hook functionality so that we can process them in the websocket connection. But for that I would add the functionality to have custom hooks defined, so that we not confuse onSend of the websocket http request connection and the onSend of the websocket communication. |
Hello,
I'm filtering the data returning from a route before being sent back to the client using onSend hook and works as expected
I also have web socket connections in my API that I would like behave the same before sending the message to the client but apparently, even if the in documentation of @fastify/websocket it states that "it will run any hooks that have been registered", it does not apply to onSend hook when sending back using connection
From testing the hook is not called entirely.
Is this the correct behaviour? How can I achieve the same result that I have using HTTP methods?
Thanks
The text was updated successfully, but these errors were encountered: