Closed a-tonchev closed 2 years ago
Just tried app.get('/') -> the websocket connection is also handled by it... or it tries to.
It is (res, req) not (req, res). Res is more frequently used than req so is helpful to have as first argument
The equivalent of saying "the server crashes" is like going to a mechanic and saying "the car doesn't work". It gives me no information whatsoever and is an example of how not to post reports.
It is (res, req) not (req, res). Res is more frequently used than req so is helpful to have as first argument
Well okay, that was the reason for crashing - i mistakenly changed them on this route. But anyway - the websocket should not call the app.any('/') handler IMHO :)
But anyway - the websocket should not call the app.any('/') handler IMHO :)
It does not call the get('/')
or any('/')
handler if you have the ws('/')
route set up. Technically websocket request is an http request, what if I want to respond with 404 or redirect etc, the get handler can do it if ws route is not declared
app.get('/*', res => res.writeStatus('404').end())
But anyway - the websocket should not call the app.any('/') handler IMHO :)
It does not call the
get('/')
orany('/')
handler if you have thews('/')
route set up. Technically websocket request is an http request, what if I want to respond with 404 or redirect etc, the get handler can do it if ws route is not declared
If that is the case, then get('/somethingElse') should also respond to a websocket call to this route. Is it a little bit inconsistency here, or am I missing something?
Anyway - it is not a big deal, we can close the issue if this is the expected behavior.
P.S. @alexhultman great great server, I am migrating right now all our servers from KOA to uWS.js
If that is the case, then get('/somethingElse') should also respond to a websocket call to this route. Is it a little bit inconsistency here, or am I missing something?
No inconsistency, if the websocket route is declared it will handle websocket route, otherwise if get or any is declared it will handle it, priority is: ws > get > any
If someone try to create a websocket connection to url that has method any, the connection enters the handler but breaks the server, because req and res have no methods:
Example Code on Server:
Call in the client:
If there is no websocket registered at this link '/' the server crashes.
I tried also to make some workaround:
But res.close is not recognized as an function. If we remove the res.close, then we get error
I think best would be if the websocket completely ignores any('/')
Insterestingly the any('/*') is not reached by the websocket if I try to connect to something like '/asdasdasd'
Edit:
The only working workaround if you don't want to use the root as websocket endpoint, or to avoid someone to crash your server if you don't use websockets: