If you modify the simple starter example with compression:
import { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';
import Fastify from 'fastify';
import { fastifyTRPCOpenApiPlugin } from 'trpc-openapi';
import { appRouter } from './router';
const fastify = Fastify();
async function main() {
await fastify.register(fastifyTRPCPlugin, { router: appRouter });
await fastify.register(fastifyTRPCOpenApiPlugin, { router: appRouter });
await server.register(import("@fastify/compress"), encodings: ["gzip", "deflate"]}) /* 👈 */
await fastify.listen({ port: 3000 });
}
main();
This will fail for responses that include very long strings (more than a kilobyte).
Logging verbosely with Fastify in these cases reveals this error:
ERROR (88453): premature close
reqId: "req-1"
err: {
"type": "Error",
"message": "premature close",
"stack":
Error: premature close
This is related to issues filed but closed as caller-errors in the fastify-compress repo:
Not entirely sure if their recommendations apply here since you do in fact use reply.send(body) in your Fastify adapter—but this does error out in a way that's eerily close, still.
Appreciate any insight you can get me—love the library otherwise, thanks!