- How to use socket.io in express routes?
- Proper way to return JSON using node or Express
- 4.x API - express()
/** * socket.id count 4 roomid * nodejs. 5.1.0 * express 4.13.3 * socket.io 1.3.7 */ app.get( '/api/v1/status/join/:roomid', function(req, res){ var roomJoined = 0; try{ roomJoined = _.pairs(io.sockets.adapter.rooms[req.params.roomid]).length; }catch(e){ console.error('/api/v1/status/join/', __line, e ); } console.log('/api/v1/status/join/', __line, req.params ); res.setHeader('Content-Type', 'application/json'); res.send( 200, JSON.stringify({result:true, type:'join', cnt: roomJoined }) ); res.end(); });
반응형
'lang > node' 카테고리의 다른 글
nodejs mysql multiquerys (0) | 2016.01.18 |
---|---|
ENOENT (0) | 2015.12.30 |
Nginx LoadBalancer + Nodejs socket.io (0) | 2015.12.16 |
socket.io 1.3.7 cluster On Nodejs 5.1.0 (0) | 2015.12.10 |
PM2 (0) | 2015.12.09 |