Last active
April 5, 2016 21:54
-
-
Save jdart/28aefe58ebb2a58d80ccca11c3d699d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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