简体   繁体   中英

Express res.render stuck in infinite loop

Steps: pull data from mongodb to populate a link on search page. Be able to click the link to take end user to the generic business page which is auto filled by mongodb. render the page with the JSON data from mongodb.

Issues: res.render gets stuck in Infinite Loop (no error is thrown also)

I've tried adding an if statement so res.render would not render again, yet still stuck in a loop.

routes/business.js

router.get('/:business', (req, res) => {
    console.log(req.params.business);
    Business.getBusinessByUrl(req.params.business, (err, business) => {
        if (err) throw err;
        res.render('business', {
            found: true,
            business_name: business.business_name,
            business_profile_image: business.business_profile_image,
            business_url: business.business_url
        });
    });
});

module.exports = router;

models/business.js

module.exports.getBusinessByUrl = function (businessUrl, callback) {
    const query = { business_url: businessUrl };
   Business.find(query, callback);
};

Here is what it looks like in the browser : Imgur

Let me know if you need any other code.

After a while of searching I couldn't find anything helpful. Eventually I figured it out. It happened to be that when I had commented out the line <div w3-include-html="file-included.html"> it stopped infinitely loading. A thank you too everyone who tried to help me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM