I'm currently working on a route that leads to the index page, which requires a secret token for access. However, I am facing an issue where the requested URL does not match the custom string I have set up. For instance, when the URL is
http://localhost:3000/?token=secret
, everything works fine. But if I enter http://localhost:3000/as?token=secret
, instead of displaying my custom 404 error page, it shows Cannot GET /as
. I need help figuring out how to properly validate this and render the error page as intended.
app.get('/', (req, res) => {
console.log(req.url); // /?token=secret
if (req.url !== `/?token=${websocket_token}`) {
res.render('error', {
title: '404 Not Found',
errorMessage: '404 Not Found'
});
return;
}
});