mirror of https://github.com/requarks/wiki
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.
20 lines
613 B
20 lines
613 B
const _ = require('lodash')
|
|
|
|
/**
|
|
* SEO Middleware
|
|
*
|
|
* @param {Express Request} req Express request object
|
|
* @param {Express Response} res Express response object
|
|
* @param {Function} next next callback function
|
|
* @return {any} void
|
|
*/
|
|
module.exports = function (req, res, next) {
|
|
if (req.path.length > 1 && _.endsWith(req.path, '/')) {
|
|
let query = req.url.slice(req.path.length) || ''
|
|
res.redirect(301, req.path.slice(0, -1) + query)
|
|
} else {
|
|
_.set(res.locals, 'pageMeta.url', `${WIKI.config.host}${req.path}`)
|
|
return next()
|
|
}
|
|
}
|