Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to log OUTGOING https requests from node within webstorm

I'm hacking together some node.js code that calls an external webservice and I'm getting bad results. I'd like to log the raw request and response so that I can inspect it.

Here's the thing: I'm not consuming the http library directly, I'm consuming it through an OAuth library.

I'm already adding debug statements in the oauth library code and I don't like it. Now it looks like I'm going to have to go into http library and start messing with that? This can't be correct.

If I was on windows, I'd fire up fiddler. A friend mentioned wireshark but wireshark tells me I have to install X11. Really? I'm not going down that rabbit hole.

Then I tried node-inspector, but I think that is for server code not client code. It says your suppose to start your node process before attaching. Well my node process is a test case (vows) that ends shortly after is starts... so no luck there.

I guess this would difficult with any stack but jeez, it makes me miss .net!

So, how can I inspect what's going over the wire when using node.js as client to external webservice on mountain lion?

thanks! Dan

like image 712
DanielEli Avatar asked Oct 18 '12 22:10

DanielEli


2 Answers

Managed to install a hook on http/https request for the same reason.

function requestLogger(httpModule){
    var original = httpModule.request
    httpModule.request = function(options, callback){
      console.log(options.href||options.proto+"://"+options.host+options.path, options.method)
      return original(options, callback)
    }
}

requestLogger(require('http'))
requestLogger(require('https'))
like image 114
uiron Avatar answered Oct 01 '22 08:10

uiron


You can check out the global-request-logger module, which uses the same technique that @uiron mentioned, but with more details.

like image 37
Johann Avatar answered Oct 01 '22 09:10

Johann