I'm using express/node now and I have the following
app.use(useridDetect);
function useridDetect (request, response, next) {
var myurl = url.parse(request.url);
if (myurl.pathname === "/cookie") {
var i = request.url.indexOf('?');
query = request.url.substr(i+4, 32);
//set userid
next();
} else {
next(); // keep the middleware chain going
}
}
app.use(require('./middleware/im')({
userid: query,
maxAge: 30 * 1000,
reapInterval: 20 * 1000,
authentication: require('./libs/authentication/' + AUTH_LIBRARY)
}));
Now it says query is undefined in the second part(Obvious I can't do this...) But how can I make the second function access that variable without using global variable? Since I will have multiple people using this script and too many global vars might be a bad idea.