help icon indicating copy to clipboard operation
help copied to clipboard

intercept network traffic using localhost as proxy

Open realrecordzLab opened this issue 4 years ago • 3 comments

  • Node.js Version: 15.4.0
  • OS: macOS 10.13.6
  • Scope (install, code, runtime, meta, other?): code
  • Module (and version) (if relevant): http, child_process

I'm using require('child_process').exec to open an application from a node cli script. I'm trying to intercept the network traffic of the opened app but I've noticed that the app opened is unable to connect to internet. Is possible to intercept the traffic using http module and after the request is logged pass it to the internet connection so the app is able to work as expected?

realrecordzLab avatar Mar 06 '21 11:03 realrecordzLab

Could you please share the code? The child process does seem to be able to connect to the internet here:

// test.js
require('child_process').
  exec('node child.js').
  stdout.pipe(process.stdout);
// child.js
require('dns').
  resolve('www.google.com', function(err) {
    if (err) {
      console.log('Not connected');
    } else {
      console.log('Connected');
    }
  });
❯ node test.js
Connected

RaisinTen avatar Mar 06 '21 13:03 RaisinTen

Could you please share the code? The child process does seem to be able to connect to the internet here:

// test.js
require('child_process').
  exec('node child.js').
  stdout.pipe(process.stdout);
// child.js
require('dns').
  resolve('www.google.com', function(err) {
    if (err) {
      console.log('Not connected');
    } else {
      console.log('Connected');
    }
  });
❯ node test.js
Connected

Here is the code.

#!/usr/bin/env node

const spawn = require('child_process').exec;
const http = require('http');

spawn('open "/Users/dev/Applications/Tv Go.app" --args \ --proxy-server=localhost:5050 \ --ingnore-certificate-errors', async (err, stdout, stderr) => {
    console.log(err, stdout, stderr);
});

http.createServer( (req, res) => {
    console.log(req, res);
}).listen(5050);

realrecordzLab avatar Mar 06 '21 16:03 realrecordzLab

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar May 10 '24 01:05 github-actions[bot]

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar Jun 09 '24 01:06 github-actions[bot]