-
-
Notifications
You must be signed in to change notification settings - Fork 83
fix(types): allow websocket server options without specifying global … #47
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
Conversation
|
Can you please add a test for these in https://github.com/fastify/fastify-websocket/tree/master/test/types? |
|
@mcollina I tried doing that but the plugin types weren't found, so wsPlugin was of type any for example and adding new types failed even if the signatures were technically correct. The tests for the plugin itself have basically no effect as wsPlugin is any: No types are checked. |
|
Can you help? |
|
@jannikkeye would a per route handler work better for you here? Maybe I’m not understanding your issue completely; if so can you provide some source code and share which parts are not getting typed / the types are breaking on. Thank you! |
|
@Ethan-Arrowood from my understanding a per route handler doesn't suffice since I have to verify incoming socket connections. And as I understand I can only do this by passing this won't work since handler is a required property of the options object passed to the plugin. this works. I cannot use the global handler though as I need access to the request as that was the only working way of getting the url of the connection and thus the query params passed from the client. At least the only way that I found. Also the request here as second parameter to the handler is incorrectly typed as url is an existing property on IcomingMessage but request is typed as FastifyRequest which it isn't entirely. |
|
As I said above the WebSocketHandler is typed incorrectly. Currently It should be typed like this: Then I don't get the type error I mentioned in my response above. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I am in a situation where I need to parse query params out of the url of a connected client and do some authentication checks. Thats currently impossible with typings provided since when I specify verifyClient as an option for the web socket server I have to specify a handler as well. I don't need a global handler though as I am handling the web socket connections on a route to have access to the request url. This PR makes handle optional to fix this issue. I guess I could also just give it a handler the does nothing as the handler will not be used by "per route web socket handlers" anyway.
Thoughts?
Checklist
npm run testandnpm run benchmark