Reputation: 5815
i have middleware say :
var app = express();
var someMiddleware = function(req, res, next){
//here i want to know for which route it's executing for eg. if i hit my app with xyz.com/xyz/123 it will hit route defined below which i want to identify in this middleware execution
};
app.get('xyz/:parameter', someMiddleware,function(req, res, next){
//some action on request
});
So, here while executing i want to check for which route middleware is exactly being called.
Upvotes: 1
Views: 185
Reputation: 33824
The only way to do this is to keep track of the incoming Request object, and to selectively log parts of it to know what URLs, Query Strings, etc., are being used in the currently executing route.
In your middleware function, for instance, you could write something like this:
var someMiddleware = function(req, res, next) {
console.log('method:', req.method);
console.log('originalUrl:', req.originalUrl);
};
The combination of the HTTP method, as well as the originalURL will give you enough information to clearly see what route is going to eventually be called.
Upvotes: 1