UNPKG

toxy

Version:

Hackable HTTP proxy to simulate server failure scenarios and network conditions

20 lines (15 loc) 418 B
const toxy = require('..') const proxy = toxy() const rules = proxy.rules const poisons = proxy.poisons proxy .forward('http://httpbin.org') .poison(poisons.inject({ code: 503, body: '{"error": "toxy injected error"}', headers: {'Content-Type': 'application/json'} })) .withRule(rules.body({ match: /hello/i })) proxy.all('/*') proxy.listen(3000) console.log('Server listening on port:', 3000)