unpkg/modules/middleware/checkBlacklist.js

26 lines
584 B
JavaScript
Raw Normal View History

2018-02-17 00:00:06 +00:00
const BlacklistAPI = require("../BlacklistAPI");
2017-11-11 20:18:13 +00:00
function checkBlacklist(req, res, next) {
2017-11-12 06:35:30 +00:00
BlacklistAPI.includesPackage(req.packageName).then(
2017-11-11 20:18:13 +00:00
blacklisted => {
// Disallow packages that have been blacklisted.
if (blacklisted) {
res
.status(403)
2017-11-25 21:25:01 +00:00
.type("text")
2018-02-17 00:00:06 +00:00
.send(`Package "${req.packageName}" is blacklisted`);
2017-11-11 20:18:13 +00:00
} else {
2018-02-17 00:00:06 +00:00
next();
2017-11-11 20:18:13 +00:00
}
},
error => {
2018-09-03 18:30:55 +00:00
console.error("Unable to fetch the blacklist: %s", error);
2017-11-11 20:18:13 +00:00
2018-09-03 18:30:55 +00:00
// Continue anyway.
next();
2017-08-17 06:03:28 +00:00
}
2018-02-17 00:00:06 +00:00
);
2017-08-17 06:03:28 +00:00
}
2018-02-17 00:00:06 +00:00
module.exports = checkBlacklist;