After Node associates mongoDB, it is found that there will be one more request for solution.

  node.js, question

I wrote this in the route:

app.get('/product/:id',Product.detail);

Details look like this:

exports.detail = function (req,res,next){
 
 var id = new mongoose.Schema.ObjectId(req.params.id).path;
 logger.info(id);
 
 ProductDB.findById(id,function(err,product){
 if(err){
 logger.error(err);
 return next(err);
 bracket
 CommentDB
 .find({product: id})
 .populate('from','name')
 .populate('reply.from reply.to','name')
 .exec(function(err,comments){
 if(err){
 logger.error(err);
 return next(err);
 bracket
 var _product = _.extend({},product);
 var _comments = _.extend({},comments);
 
 return res.render('detail',{
 title: _product.title,
 product: _product,
 comments: _comments
 });
 });
 });
 };

After service, the page is normal.

http://localhost:3000/product/56335734f8e5b62182dc0d35

However, it was found that there was a multiple request, and the request did not get params.id, resulting in momgoose reporting CastError as follows:

GET /product/56335734f8e5b62182dc0d35 304
 zhishifan started on port: 3000
 GET /libs/jquery/dist/jquery.min.js 304
 GET /libs/bootstrap/dist/css/bootstrap.min.css 304
 GET /libs/bootstrap/dist/js/bootstrap.min.js 304
 GET /product/undefined 304
 zhishifan started on port: 3000
 GET /js/comment.js 304
 GET /libs/jquery/dist/jquery.min.map 304

I really didn’t figure out where the request came from, and there was no duplicate definition of routing inside, asking for guidance.

In addition, if only the simplest render is used for requests, there will be no redundant requests, so I think it should not be the problem of route duplication:

exports.detail = function (req,res,next){
 res.render('detail',{
 title: 'hi'
 });
 };
 
 GET /product/56335734f8e5b62182dc0d35 200
 zhishifan started on port: 3000
 GET /libs/jquery/dist/jquery.min.js 304
 GET /libs/bootstrap/dist/css/bootstrap.min.css 304
 GET /libs/bootstrap/dist/js/bootstrap.min.js 304
 GET /js/comment.js 304
 GET /libs/jquery/dist/jquery.min.map 304

Your detail function has no return value