2019-01-06 00:50:05 +00:00
|
|
|
import createSearch from '../utils/createSearch';
|
2018-05-19 15:34:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect old URLs that we no longer support.
|
|
|
|
*/
|
2019-01-06 00:50:05 +00:00
|
|
|
export default function redirectLegacyURLs(req, res, next) {
|
2018-05-19 15:34:36 +00:00
|
|
|
// 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();
|
|
|
|
}
|