From 4e8e7fa6cf871672ef459878a1857dda87edf0c6 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Fri, 25 Apr 2025 15:35:16 -0700 Subject: [PATCH] tRPC fetchers: debug wire curl --- src/server/wire.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/server/wire.ts b/src/server/wire.ts index 79f041939..9878a50f5 100644 --- a/src/server/wire.ts +++ b/src/server/wire.ts @@ -1,5 +1,5 @@ /// set this to true to see the tRPC and fetch requests made by the server -export const SERVER_DEBUG_WIRE = false; // +export const SERVER_DEBUG_WIRE = true; // export class ServerFetchError extends Error { @@ -96,8 +96,18 @@ export function debugGenerateCurlCommand(method: 'GET' | 'POST' | 'DELETE' | 'PU for (const header in headersRecord) curl += `-H '${header}: ${headersRecord[header]}' `; - if (method === 'POST' && body) - curl += `-d '${JSON.stringify(body)}'`; + if (method === 'POST' && body) { + if (body instanceof FormData) { + for (const [key, value] of body.entries()) { + if (value instanceof File) { + curl += `-F '${key}=@${value.name}' `; + } else { + curl += `-F '${key}=${value}' `; + } + } + } else + curl += `-d '${JSON.stringify(body)}'`; + } return curl; }