Getting corrupted binary responses instead of JSON from Hono gateway service with axios

Hi everyone! I'm having an issue with my Hono-based API gateway that forwards requests to microservices. I’m receiving corrupted binary responses instead of the expected JSON when using axios or fetch from my React Native frontend. Problem: Requests return binary-like data instead of proper JSON:
"\u0015`\u0000..."
"\u0015`\u0000..."
Expected response:
{
"success": true,
"message": "Login successful",
"data": { "session": { "access_token": "eyJ...", "refresh_token": "eyJ...", "expires_at": 1234567890 } }
}
{
"success": true,
"message": "Login successful",
"data": { "session": { "access_token": "eyJ...", "refresh_token": "eyJ...", "expires_at": 1234567890 } }
}
Environment: - Hono v4.8.4 - Cloudflare Workers - Axios v1.10.0 - React Native with Expo Setup: My gateway service built with Hono forwards requests to the auth microservice, which returns proper JSON when called directly. Gateway code:
const response = await axiosInstance.request(axiosConfig);
return new Response(JSON.stringify(response.data), {
status: response.status,
headers: {
"Content-Type": response.headers["content-type"] || "application/json",
},
});
const response = await axiosInstance.request(axiosConfig);
return new Response(JSON.stringify(response.data), {
status: response.status,
headers: {
"Content-Type": response.headers["content-type"] || "application/json",
},
});
What I've tried: 1. Different axios versions 2. Native fetch 3. Direct calls to the auth service (worked fine) 4. Adjusting Content-Type headers 5. Checking network response (shows corrupted data) 6. Added JSON parsing in interceptors 7. Verified auth service with curl Key observations: - Works fine when calling the auth service directly. - The issue only occurs through the Hono gateway. - Both axios and fetch result in the same corrupted response. Could this be related to response compression, double JSON stringification, header forwarding, or a Cloudflare Workers behavior? Any suggestions would be appreciated!
2 Replies
ambergristle
ambergristle3mo ago
if you're always returning json, why forward the response content type header at all?
Arjix
Arjix3mo ago
^^ and why are you not using the ctx.json helper? return ctx.json(response.data, response.status)

Did you find this page helpful?