Created
August 23, 2022 07:14
-
-
Save TWinsnes/54d9b7f2f9383509c051e0f6a24b43df to your computer and use it in GitHub Desktop.
Quick nodejs Proxy for debugging https requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Update the target to be the taget url you are hitting | |
// | |
// run this standalone and in your app send traffic to localhost:8000 | |
var http = require('http'), | |
httpProxy = require('http-proxy'); | |
const proxy = httpProxy.createProxyServer({ | |
target: 'https://target.url.com', | |
secure: false | |
}) | |
proxy.listen(8000) | |
proxy.on('proxyReq', async function (proxyReq, req, res) { | |
const buffers = [] | |
for await (const chunk of req) { | |
buffers.push(chunk) | |
} | |
const data = Buffer.concat(buffers).toString() | |
console.log(data) | |
console.log(JSON.stringify(proxyReq.getHeaders())) | |
console.log(`${proxyReq.protocol}//${proxyReq.host}${proxyReq.path}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment