aykleeA
tRPC10mo ago
4 replies
ayklee

TRPC giving 502 errors with jsonl header

I'm encountering a 502 Bad Gateway error when making a GET request to my tRPC endpoint in a production environment. This only happens when using the trpc-accept: application/jsonl header.

Environment
Runtime: bun
Deployment Stack: docker → nginx → cloudflare
tRPC version:
"@trpc/client": "^11.0.0-rc.446",
"@trpc/react-query": "^11.0.0-rc.446",
"@trpc/server": "^11.0.0-rc.446",

Request Example
Here is the frontend request triggering the issue:
await fetch("https://<cloudflare_url>/api/trpc/admin.getExams?batch=1&input=%7B%220%22%3A%7B%22json%22%3A%2230494%22%7D%7D", {
  credentials: "include",
  headers: {
    "User-Agent": "Mozilla/5.0 ...",
    "Accept": "*/*",
    "Accept-Language": "en-US,en;q=0.5",
    "content-type": "application/json",
    "trpc-accept": "application/jsonl",  // ← Causes 502
    "x-trpc-source": "nextjs-react",
    ...
  },
  referrer: "https://<cloudflare_url>/admin/p/30494",
  method: "GET",
  mode: "cors"
});



Behavior
✅ Local Docker: Request works as expected.
❌ Production (Docker + Nginx + Cloudflare): Returns a 502 Bad Gateway.

When I remove the trpc-accept header or change it to "application/json", the request works fine in production.


Additional Notes
In the browser dev tools, when this request fails locally (still using Docker), the Network > Response panel shows:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data


This seems to be an issue with how application/jsonl is handled, either by nginx, cloudflare, or the bun server itself.


What I’ve Tried
Changing trpc-accept to application/json → Works
Removing trpc-accept altogether → Works
Reproduced only in production (cloudflare + nginx)
Was this page helpful?