This is ebayApi.handleParams :
handleParams : (req, res, next) => {
for(var param in req.params){
for(var key in ebayApi.request){
param == key ? ebayApi.request[key] = req.params[param] : key = key
}
}
next();
},
When I do
app.use(ebayApi.handleParams);
The middleware gets executed, but req.params doesn't have the same value whenever it's inside
app.get( '/search', (req, res) => {
});
So I'm forced to use middleware like this
app.get( '/search', ebayApi.handleParams, (req, res) => {
});
Is there a way to fix it? I want to get rid of all the extra typing whenever I create a new route.. It's a middleware that needs to be applied to all incoming requests..
Anyone still interested in the solution?
What I did was create an array of each route that has to go trough the middleware, and then loop trough the array and apply it this way, instead of hard coding it for every route.
var routes = [ '/profile/:UserID', '/categories/:CategoryID', '/item/:itemId', '/search/:keywords/:filter*?', '/keywords/:keywords']
for(var route in routes){
app.all(routes[route], middleware.ebay.handleParams);
}