Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const getLatestVersion = (req, res) => {
const scope = pkgName.split('/')[0];
const regUrl = registryUrl(scope);
const pkgUrl = url.resolve(regUrl, encodeURIComponent(pkgName).replace(/^%40/, '@'));
const authInfo = registryAuthToken(regUrl);
const headers = {};
if (authInfo) {
headers.Authorization = `${authInfo.type} ${authInfo.token}`;
}
request
.get(pkgUrl)
.set(headers)
.end((err, _res) => {
if (err) {
res.status(ERR_INTERNAL_SERVER_ERROR).send({
msg: `Failed to connect to ${pkgUrl}: code=${err.code}`
});
return;
}