@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({
    logger,
  });
  await server.register(import('@fastify/compress'), {
    global: true,
    threshold: 1024,
  });

  await server.start();
}

main();

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

    await server.register(redwoodFastifyGraphQLServer, {
      redwood: {
        apiRootPath,
        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 and desploying using the docker api_serve stage

Hi all! We did have a bug where you could not configure the API server as you describe here.

We have addressed this here but the fix has not yet been released. It should be released as part of 7.7.0 which will come out this coming week :crossed_fingers:

The updated docs are live on the canary version of the docs here.

Thanks @Josh-Walker-GM !

@Josh-Walker-GM am I reading the PR correctly that this does not work for requests to /graphql? That was the main use case I was looking for when making this thread and, after updating to rw 7.7.1 it seems requests to /graphql are still not being compressed.

edit
to add onto the above if I have a api/src/server.ts with the following

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

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

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

  await server.start();
}

main();

responses from /graphql are not compressed. If I add

  await server.register(import('@fastify/compress'), {
        global: true,
        threshold: 1024,
      });

directly to the rw package server.ts at line 111 then responses from /graphql are compressed as expected.