Forward all
mircohacker opened this issue · 4 comments
Hi,
is it posible proxy requests to all hosts and only poison specific routes?
proxy
.forward('*')
proxy
.forward('http://myhost')
.get('/test')
.poison(poisons.abort())
Yes, please, see this example: https://github.com/h2non/toxy/blob/master/examples/routes.js
@tomas-fp, in your example, aren't you forwarding everything to 'http://httpbin.org'? Ohmen is asking if you can request to all hosts.
I'm currently trying to achieve something similar, and can't seem to get something working.
You can do that by registering your custom middleware and a custom rule that only activates a some traffic poisoning selectively. E.g:
proxy
.use(defineHostTargetMiddleware)
.poison(anEvilPoison)
.withRule(filterByHost)
@h2non I see, could you elaborate on what we be included within defineHostTargetMiddleware
?
With the below code, I'm trying to position toxy as a middleman to inject poison into any request made to it, rather than force requests to a specific forwarding host.
proxy.use(function(req, res, next) {
req.rocky.options.target = req.url;
next();
})
.poison(poisons.abort())
.withRule(toxy.rules.probability(50));
proxy.all('/*');
proxy.listen(3000);
Any guidance would be great!
EDIT:
I was able to get this working with the below code:
proxy.forward('/')
.all('/*')
.use(function(req, res, next) {
req.rocky.options.target = 'http://' + req.headers.host;
next();
})
.poison(poisons.abort())
.withRule(toxy.rules.probability(50));
proxy.listen(3000);