Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending NodeJs Axios requests via Fiddler

I am using Windows + Visual studio code to developer a Node JS API. I am using Axios to submit rest requests from NodeJs to third party API's.

I would like to inspect the packets sent from my Node server to the third party backend via Fiddler, however I have been having a hard time getting Axios to proxy through 127.0.0.1 port 8888.

Ideally it would be an easy global variable to set to turn on/off the proxy. the thing I have tried is:

axios.defaults.proxy = { host: "127.0.0.1", port:8888}

axios.defaults.proxy = { host: "127.0.0.1", port:8888, protocol: "http"}

axios.post(url: <api>, {post:data}, {proxy: {host: "127.0.0.1", "8888"} });

and a alot of different variations of the above. when the proxy is on, it won't complete the request.

like image 516
Michael Avatar asked Nov 08 '18 23:11

Michael


1 Answers

Is the server you are trying to reach using https? This is a problem with axios that they seem to be having trouble solving.

A workaround that will allow you to proxy through Fiddler is to use an HTTPS-over-HTTP tunnel. Jan Molak wrote this nice article about the scenario of sending a request to an https server through an http proxy. The following code has worked for me when running requests through Fiddler:

const axios = require('axios');
const tunnel = require('tunnel');

const axiosInstance = axios.create({
  httpsAgent = tunnel.httpsOverHttp({
    host: '127.0.0.1',
    port: 8888,
  }),
  proxy: false,
});

axiosInstance.post(/* ... */);
like image 109
dpopp07 Avatar answered Oct 18 '22 05:10

dpopp07