morpheus
morpheus

Reputation: 20330

Unable to see http traffic from/to my NodeJS app in Charles [mac]

I am running Charles to inspect HTTP traffic between a node js client and a service running locally on my machine (a Mac). I am able to access the service but don't see any trace in Charles. I have tried replacing localhost with my machine's IP name but still no trace. If I type the service URL in Chrome I do see a trace. Anyone knows how to fix this?

Here is my nodejs code:

var thrift = require('thrift'); // I use Apache Thrift
var myService = require('./gen-nodejs/MyService'); // this is code generated by thrift compiler
var transport = thrift.TBufferedTransport();
var protocol = thrift.TBinaryProtocol();
var connection = thrift.createHttpConnection("localhost", 5331, {
  transport : transport,
  protocol : protocol,
  path: '/myhandler',
});

connection.on('error', function(err) {
    console.log(err);
});

// Create a client with the connection
var client = thrift.createHttpClient(myService, connection);
console.log('calling getTotalJobCount...');

client.getTotalJobCount(function(count)
{
    console.log('total job count = ' + count);
});

and my proxy settings: enter image description here

Upvotes: 1

Views: 895

Answers (1)

morpheus
morpheus

Reputation: 20330

fixed this myself with help of this link. Charles intercepts the traffic crossing the system proxy which is 127.0.0.1:8888 on my mac. Here is proper code:

// give path to the proxy in argument to createHttpConnection
var connection = thrift.createHttpConnection('127.0.0.1', 8888, {
  transport : transport,
  protocol : protocol,
  path: 'http://localhost:5331/myhandler', // give the actual URL you want to connect to here
});

In addition need to use thrift.TBufferedTransport instead of thrift.TBufferedTransport() and thrift.TBinaryProtocol instead of thrift.TBinaryProtocol()

Upvotes: 1

Related Questions