I am using Node.js and Express and I have the following routing :
app.get(\'/\', function(req,res){
locals.date = new Date().toLocaleDateString();
r
I'm adding this answer because I had too many issues with other solutions.
/**
* @param {express.Request} req
* @param {express.Response} res
* @param {express.NextFunction} next
* @return {void}
*/
function checkTrailingSlash(req, res, next) {
const trailingSlashUrl = req.baseUrl + req.url;
if (req.originalUrl !== trailingSlashUrl) {
res.redirect(301, trailingSlashUrl);
} else {
next();
}
}
router.use(checkTrailingSlash);
This will translate:
/page ==> /page/
/page?query=value ==> /page/?query=value