unpkg/modules/middleware/redirectLegacyURLs.js

24 lines
611 B
JavaScript
Raw Normal View History

2018-12-17 17:38:05 +00:00
const createSearch = require('../utils/createSearch');
2018-05-19 15:34:36 +00:00
/**
* Redirect old URLs that we no longer support.
*/
function redirectLegacyURLs(req, res, next) {
// Permanently redirect /_meta/path to /path?meta.
if (req.path.match(/^\/_meta\//)) {
2018-12-17 17:38:05 +00:00
req.query.meta = '';
2018-05-19 15:34:36 +00:00
return res.redirect(301, req.path.substr(6) + createSearch(req.query));
}
// Permanently redirect /path?json => /path?meta
if (req.query.json != null) {
delete req.query.json;
2018-12-17 17:38:05 +00:00
req.query.meta = '';
2018-05-19 15:34:36 +00:00
return res.redirect(301, req.path + createSearch(req.query));
}
next();
}
module.exports = redirectLegacyURLs;