nl_tokens: A small helper which allows us to just use all of our existing . / middleware / * . js and . / params / * . js targeted at express with socket . io . This is in an effort to reuse as much code as possible and lower the probability of oops bugs as in Oops! I changed it in middleware / ns . js and tested it but I forgot got to update it in io . js : ( .
pl_tokens: function applyMiddleware ( socket , req , done ) { // A stub for the `res` argument express usually provides. var res = { } ; // Map the socket.io request into a `req` like stub as well. var params = clone ( req ) ; assign ( params , { session_id : socket . decoded_token . session_id , deployment_id : socket . decoded_token . deployment_id } ) ; req = { params : params , query : { } , body : { } } ; // Yay! Now we can just use all of our existing middleware! series ( { 'Load token data' : partial ( Token . load , socket . decoded_token , req ) , 'Add typed param getters' : <mask> ( typedParams , req , res ) , 'Parse the namespace param if presented' : function ( next ) { unpackNamespaceParam ( req , res , next , req . params . ns ) ; } , 'The collection must already exist' : partial ( collectionRequired , req , res ) , 'Parse sample options' : partial ( sampleOptions , req , res ) } , function ( err ) { if ( err ) { return done ( err ) ; } debug ( 'middleware applied successfully' , req ) ; done ( null , req ) ; } ) ; }