express.io icon indicating copy to clipboard operation
express.io copied to clipboard

Catch All Events in Server Side

Open american423 opened this issue 11 years ago • 8 comments

I would like to catch all events in server side in order to save all logs.

Is it possible to do something like this? (using wild card)

app.io.route('*', function(req) {

});

What I need to do is saving all event logs in mongoDB.

If there is any way, please give me an advise. (it is ok to override some code)

american423 avatar Mar 06 '13 03:03 american423

Do you want your logging callback to run and then the route?

techpines avatar Mar 06 '13 23:03 techpines

Yes. It is great to have a logging callback!

american423 avatar Mar 07 '13 01:03 american423

Has this issue been addressed? I am trying to log out the broadcast event (to see how many times it broadcasts based on how many sockets are open), but I am unable to do this in a callback. I try to listen to the event on the global app variable as well, like so..

app.io.sockets.on('connection', function(socket){ socket.on('broadcast', function(){ console.log('msg broadcast'); }); });

But this too is not logging out the event. Any guidance would be greatly appreciated (fairly new to socket.io so I might be completely missing something). Thanks in advance!

svignara avatar Apr 22 '13 20:04 svignara

I need something like this too.

In my case I have list of method allowed only for authenticated users. It it will be great to check user status (+authorization) before calling app.io.route

Maybe we can use some middlerware?

my view on this situation

app.io.validate(function(method, req) { var allow = ['foo', 'bar']; if (!req.session.authenticated && method id allow) { req.respond('denied!!'); } });

vinnitu avatar Aug 07 '13 16:08 vinnitu

I need something like this too. I'm trying to implement a "fallback event", in other words, an event that is called when the called event is not defined. Anybody knows if this is possible?

Gomes81 avatar Mar 11 '14 17:03 Gomes81

http://stackoverflow.com/questions/9001143/socket-io-how-do-i-handle-all-incoming-messages-on-the-server

There's a good starting place for whoever is going to code it into express.io :)

silkcom avatar Mar 11 '14 17:03 silkcom

Thanks that works, I already saw that, but I was thinking that was only for client side, but works great on the server side to

Gomes81 avatar Mar 11 '14 18:03 Gomes81

I would really like to see this built into the core of express.io app.io.route('*'...) seems like it would be the best syntax for that.

silkcom avatar Mar 11 '14 19:03 silkcom