Skip to content

Instantly share code, notes, and snippets.

@jdart
Last active April 5, 2016 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdart/28aefe58ebb2a58d80ccca11c3d699d3 to your computer and use it in GitHub Desktop.
Save jdart/28aefe58ebb2a58d80ccca11c3d699d3 to your computer and use it in GitHub Desktop.
var toxy = require('toxy')
var poisons = toxy.poisons
var rules = toxy.rules
// Create a new toxy proxy
var proxy = toxy()
// Default server to forward incoming traffic
proxy
.forward('https://foo.bar/')
.options({ secure: false })
proxy.all('/*')
.poison(poisons.inject({
code: 200,
headers: {
'Access-Control-Allow-Origin': 'http://localhost:8100',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Headers': 'accept, accept-language, content-type',
}
}))
.withRule(rules.method(['OPTIONS']))
.withRule(rules.probability(100));
// Register global poisons and rules
var route = proxy
.all('/*')
route.poison(poisons.inject({code: 500}))
.withRule(rules.probability(30))
.withRule(rules.method(['GET', 'POST', 'PUT', 'DELETE']))
route.poison(poisons.abort(1000))
.withRule(rules.probability(30))
.withRule(rules.method(['GET', 'POST', 'PUT', 'DELETE']))
proxy.listen(3000)
console.log('Server listening on port:', 3000)
console.log('Test it:', 'http://localhost:3000/image/jpeg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment