UNPKG

chaos-injector

Version:

Chaos engineering middleware for testing API resilience

16 lines (12 loc) 405 B
// ChaosInjector/middlewares/responseDelay.js function responseDelay(options = {}) { const { delayRange = [100, 2000] } = options; const [minDelay, maxDelay] = delayRange; return function(req, res, next) { const delay = Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay; setTimeout(() => { next(); }, delay); }; } module.exports = responseDelay;