UNPKG

toxy

Version:

Hackable HTTP proxy to simulate server failure scenarios and network conditions

13 lines (9 loc) 298 B
module.exports = function probability (num) { const percent = +Math.min(num, 100) || 50 return function probability (req, res, next) { if (percent > 99) return next() const rand = Math.round(Math.random() * 100) const notMatches = rand > percent next(null, notMatches) } }