You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the req.on('end", ... ), proxy.web does not work.
I want to either proxy or mock based on request body.
var proxy = httpProxy.createProxyServer({});
...
var body = [];
req.on('data', function(chunk) {
body.push(chunk);
}).on('end', function() {
body = Buffer.concat(body).toString();
// At this point, we have the headers, method, url and body, and can now
// do whatever we need to in order to respond to this request.
if(req.url.indexOf("/something") >= 0) {
var a = JSON.parse(body);
if(a.id == "testid") {
console.log("mock");
res.writeHead(200);
res.end("predefined response");
return;
}
}
console.log("proxy");
proxy.web(req, res, { forward: 'http://real_url' });
});
The text was updated successfully, but these errors were encountered:
In the req.on('end", ... ), proxy.web does not work.
I want to either proxy or mock based on request body.
The text was updated successfully, but these errors were encountered: