To intercept the request, before your '.middleware/im'
can get to it, you need to create your own middlware, which is surprisingly simple (the following goes before your call to app.use(require('./middleware/im')({ ...
):
app.use(cookieDetect);
function cookieDetect (request, response, next) {
if (request.url === "/cookie") {
// do your stuff here
} else {
next(); // keep the middleware chain going
}
}
Btw, as a JavaScript syntactical note, when you use function declarations (different than var myFunc = function () { ...
), "scope hoisting" happens: that particular function declaration is available at the very beginning of that scope-level's execution, instead of from where it appears in the code. Which is why I'm able to app.use
it before it appears in the code.