You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
627 B

  1. 'use strict'
  2. const _ = require('lodash')
  3. /**
  4. * SEO Middleware
  5. *
  6. * @param {Express Request} req Express request object
  7. * @param {Express Response} res Express response object
  8. * @param {Function} next next callback function
  9. * @return {any} void
  10. */
  11. module.exports = function (req, res, next) {
  12. if (req.path.length > 1 && _.endsWith(req.path, '/')) {
  13. let query = req.url.slice(req.path.length) || ''
  14. res.redirect(301, req.path.slice(0, -1) + query)
  15. } else {
  16. _.set(res.locals, 'pageMeta.url', `${WIKI.config.host}${req.path}`)
  17. return next()
  18. }
  19. }