koajs / koa.io

[MAINTAINERS WANTED] Realtime web framework combine koa and socket.io.
429 stars 52 forks source link

fix multiple namespaces having the same router and calling the routes multiple times #13

Closed rashfael closed 9 years ago

rashfael commented 9 years ago

If you have multiple namespaces or multiple instances of socket.io (like in the tests), you get multiple calls on a route for one socket call, because the router gets initialized once, globally.

With this fix, the router now gets initialized once per namespace object by checking if a router property already exists. The only way to change the constructor/function of socket.io/lib/namespace that came to my mind are doing dark things with the require cache, and I did not want to go there.

Added a test for the echo route.

rashfael commented 9 years ago

Just thought about a much better way to solve this problem, a getter.

ariporad commented 9 years ago

@rashfael: Did you implement the getter? Because if so, I'll merge

rashfael commented 9 years ago

Yes, in 22eef9a0.