Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ cli.command("proxy")
.requiredOption("-p, --port <number>", "Port to listen on")
.requiredOption("-t, --target <url>", "Target URL to proxy to")
.option("--pretty", "Pretty-print the JSON")
.option("--log-responses", "Log responses in addition to requests")
.action(async (options) => {
const port = parseInt(options.port, 10);
const targetUrl = new URL(options.target);
Expand Down Expand Up @@ -256,6 +257,7 @@ cli.command("proxy")
// Stream response data immediately to client
proxyRes.on("data", (chunk) => {
res.write(chunk);
if(options.logResponses) process.stdout.write(chunk);
});

proxyRes.on("end", () => {
Expand Down Expand Up @@ -293,7 +295,7 @@ cli.command("proxy")
req.on("end", () => {
if(options.pretty) console.log(JSON.stringify(JSON.parse(buffer.join()), null, 2));
else process.stdout.write("\n");
console.log(`[${timestamp}] ✅ Request complete`);
stderrLog("✅ Request complete");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed sometimes we do console.error(, stderrLog(, and console.log( in this file. what are the different situations in which we would use one over the other?

proxyReq.end();
});

Expand Down