How to check the response of requests through node.js

I am trying to use node.js to install a proxy server. The idea is to get all the web service calls made into one web service through the node.js proxy to easily check and debug web service calls.

To do this, I am trying to use the following code to proxy requests:

var url = require('url'), http = require('http'), acceptor = http.createServer().listen(8008); acceptor.on('request', function(request, response) { console.log('request ' + request.url); request.pause(); var options = url.parse(request.url); options.headers = request.headers; options.method = request.method; options.agent = false; var connector = http.request(options, function(serverResponse) { serverResponse.pause(); response.writeHeader(serverResponse.statusCode, serverResponse.headers); serverResponse.pipe(response); serverResponse.resume(); }); request.pipe(connector); request.resume(); }); 

But I can not figure out where to check / reset the file for the answer. With the node inspector, I looked at the response object line by line: serverResponse.pipe (response); but the response body is not yet available.

I found the following question node.js proxy request site , but it is written in CoffeeScript.

+4
source share
1 answer

The idea is to write your own 'data' handler and do not use pipe() .
You cannot eavesdrop on data after you stream.

0
source

Source: https://habr.com/ru/post/1484917/


All Articles