Break up parseURL middleware

This commit is contained in:
Michael Jackson
2018-05-19 08:34:36 -07:00
parent c6a6b1ffc9
commit 269b756aeb
8 changed files with 103 additions and 107 deletions

View File

@ -0,0 +1,23 @@
const createSearch = require("./utils/createSearch");
/**
* 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\//)) {
req.query.meta = "";
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;
req.query.meta = "";
return res.redirect(301, req.path + createSearch(req.query));
}
next();
}
module.exports = redirectLegacyURLs;