Remove unneeded req params related to the URL

This commit is contained in:
Michael Jackson
2019-08-08 15:13:19 -07:00
parent 091e13b46a
commit 6ad61a984f
11 changed files with 131 additions and 165 deletions

View File

@ -0,0 +1,19 @@
import parsePackagePathname from '../utils/parsePackagePathname.js';
/**
* Parse the pathname in the URL. Reject invalid URLs.
*/
export default function validatePackagePathname(req, res, next) {
const parsed = parsePackagePathname(req.path);
if (parsed == null) {
return res.status(403).send({ error: `Invalid URL: ${req.path}` });
}
req.packageName = parsed.packageName;
req.packageVersion = parsed.packageVersion;
req.packageSpec = parsed.packageSpec;
req.filename = parsed.filename;
next();
}