-
Notifications
You must be signed in to change notification settings - Fork 140
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
Question about fake .get method #33
Comments
I'm not the original author, but I had to dive a little bit into this library myself. So, I can't guarantee that what I say is correct, this is only my own possibly flawed understanding ;) In add-ws-method.js, the fake .get handler is explained quite well. If you say, for example, |
Hi @dcousens, @bartim's explanation is very good IMO. The "fake get handler" is just a way to get the express router to handle WS requests. The express framework doesn't have a concept of WebSockets, so we let the express router handle the WS upgrade request as a regular GET request instead. This should be OK since these upgrade requests are simple GET requests with an 'Upgrade' header present anyway. But you'll also notice that the signature of the WS handler functions does not match the signature of the regular GET/POST/PUT+++ handlers as defined by the express framework. This means that we need a way to distinguish our WebSocket upgrade requests from our regular GET requests. That's were the fake handler you're referring to comes into the picture. See @bartim's comment for details on how & where the handler is added. |
Thanks guys :) |
BTW, I ran into an issue with this. I have routes like My short term solution, which seems to work, is to make sure that the call to I'm a little nervous about this because I feel like there will be corner cases where it still might fail (e.g., if I happened to have a route that ended in Ideally, it would be better if the fake URL were rooted in an entirely different URL hierarchy so there was no overlap in the routes. I suppose the |
In
index.js
, it mentions:What is this fake
.get
handler?The text was updated successfully, but these errors were encountered: