@fastify/compress Does Not Work if Registered in New Server File

If following the documentation for registering @fastify/compress using the new server.ts file it seems that it’s too late to successfully register the plugin as a global hook. With the below configuration dev tools show no compression taking place.

import { createServer } from '@redwoodjs/api-server';

import { logger } from 'src/lib/logger';

async function main() {
  const server = await createServer({
  await server.register(import('@fastify/compress'), {
    global: true,
    threshold: 1024,

  await server.start();


However, if redwood’s createServer is patched such that the await server.register(import('@fastify/compress')... occurs before

    await server.register(redwoodFastifyGraphQLServer, {
      redwood: {
        graphql: __rw_graphqlOptions

compression functions on a global basis as expected.

I know @fastify/compress has the potential to conflict with other plugins if not registered first as the compress plugin readme does call out:

Important note! If you are using @fastify/compress plugin together with @fastify/static plugin, you must register the @fastify/compress (with global hook) before registering @fastify/static.

However, as far as I can tell that’s not being brought into scope during redwood’s createServer but maybe I missed it or there is some other conflicting plugin I’m not seeing – not terribly familiar with fastify.

Hello - seeing the same behavior: compression is not working when following the redwoodjs docs.

  • I get multiple random errors “ERR_STREAM_PREMATURE_CLOSE” when either compress or rate-limit are registered