由于这个中间件,我收到错误。没有这一切一切顺利

时间:2018-02-11 04:36:26

标签: javascript node.js mongodb express mongoose

function checkCampgroundOwnership(req,res,next){
    if(req.isAuthenticated()){
        Campground.findById(req.params.id , function(err,foundCampground){
            if(err){
                res.redirect("back");
            }else{
                //does the user own the campground
                if(foundCampground.author.id.equals(req.user._id)) {
                    next();                                                    
                    //res.render("/campgrounds/edit",{campground:foundCampground});
                }
                else{
                    res.redirect("back");
                }
            }
        });
    }
    else{
        res.redirect("/login");
    }
}

这里的中间件有问题吗?请帮忙..

router.get("/campgrounds/:id/edit",checkCampgroundOwnership, 
function(req,res){   
Campground.findById(req.params.id , function(err,foundCampground){
       if(err){
           res.redirect("/campgrounds");
              } else{
            res.render("campground/edit",{campground: foundCampground});
              }
        });

});

router.put("/campgrounds/:id",checkCampgroundOwnership, function(req,res){
Campground.findByIdAndUpdate(req.params.id, req.body.campground
,function(err, updatedCampground){
        if(err){
            res.redirect("/campgrounds");
            console.log("It's working bad");
        }else{

            res.redirect("/campgrounds/" + req.params.id );
            console.log("It's working fine");
        }

}); });

这些路线是编辑和更新博客文章,我收到错误"没有指定默认引擎,也没有提供扩展名。"

0 个答案:

没有答案