0

I am basically trying to say, if someone types into the browser, xxx.com/homy, instead of xxx.com/home, how do I redirect them to a 404 page? here's my index.js file. I am using node.js

// Direct to View Registrations
router.get('/viewRegistration', auth.ensureAuthenticated, function(req, res, next) {

var adminActive = ""
UtilRole.roleCheck(req, res, 'ADMIN', (response) => {

    adminActive = response != undefined ? response : false


    const user = JSON.parse(req.session.passport.user)


    var query = "SELECT * FROM table WHERE email = '" + user.emailAddress + "'";
    ibmdb.open(DBCredentials.getDBCredentials(), function(err, conn) {
        if (err) return res.send('sorry, were unable to establish a connection to the database. Please try again later.');
        conn.query(query, function(err, rows) {
            if (err) {
                Response.writeHead(404);
            }


            for (var i = 0; i < rows.length; i++) {
                console.log(rows[i])
            }
           
            res.render('viewRegistration', {
                page_title: "viewRegistration",
                data: rows,
                user,
                role: adminActive
            });

            return conn.close(function() {
                console.log('closed /viewRegistration');

            });
        });
    });
})

})

module.exports = router;

Gianluca
  • 900
  • 8
  • 27
  • 3
    You haven't specified your server framework, not shared any code. How can we help you? – Andrey Popov May 19 '21 at 13:48
  • Does this answer your question? [How to redirect 404 errors to a page in ExpressJS?](https://stackoverflow.com/questions/6528876/how-to-redirect-404-errors-to-a-page-in-expressjs) – Charlie Schliesser May 19 '21 at 13:55

0 Answers0