How to get the value of parameters through the app.use?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
14 views
The point is, the application at start writes, updates, or removes the stale routes in the database. Information such as the route name, description, etc. can be changed, so that when moving along this route to call the middleware which will load from the database information and write it for example in the res.locals.title, etc. With routes without parameters is no problem, but what about routes with parameters for example '/:id'

Example implementation:
app.use(function(req, res, next) { // Search in the database information about the route Routes.findOne({'path' : req.url}, function(err, rout) { /* While a temporary solution because the path generated by '/admin/routes/5aeb87729c92911740622fc5', in was is '/admin/routes/:id' */ if (rout == null) { Res. locals.title = req.url } // Otherwise, send the data from the database else { Res. locals.title = rout.title } next() }) })


Maybe someone that is prompt, MB there is another way to implement this functionality?
by | 14 views

1 Answer

0 like 0 dislike
Maybe it's spike-Cycling method, but the other has not yet come up and only works if the parameters are not greater than 1, well for starters and then forward, still be drunk.

Here is my implementation:
app.use(function (req, res, next) { Routes.findOne({'path' : req.originalUrl}, function(err, pageInfo) { if(err) { Res. locals.title = 'Error reading the page information from DB'; Res. locals.description = err; console.log(err); next(); } if(pageInfo == null) { var search = req.originalUrl.split('/'); search.splice(-1,1,':'); search = search.join('/'); Routes.findOne({'path' : {$regex: search}}, function(err, pageInfo){ if(err) { Res. locals.title = 'Error reading the page information from DB'; Res. locals.description = err; console.log(err); next(); } if(pageInfo == null) { Res. locals.title = 'Finished script brute'; Res. locals.description = err; console.log(err); next(); } else { Res. locals.title = pageInfo.title; Res. locals.description = pageInfo.description; next() } }) } else { Res. locals.title = pageInfo.title; Res. locals.description = pageInfo.description; next() } }) });


MB someone will be additions, I'll be glad
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users