Skip to content

Merge headers #405

@lilouartz

Description

@lilouartz

These seems to be an issue, where if I send headers using Fastify, then anything that gets added by Remix is overriden, e.g.

Here I am adding link header:

await app.register(async (instance) => {
  instance.decorateRequest('cspNonce', null);

  instance.removeAllContentTypeParsers();

  instance.addContentTypeParser('*', (_request, payload, done) => {
    done(null, payload);
  });

  const handler = createRequestHandler({
    build: serverBuild,
    getLoadContext(request) {
      return {
        nonce: request.cspNonce,
        session: request.session as unknown as Session,
        visitor: request.visitor,
      };
    },
    mode: 'production',
  });

  instance.all('*', async (request, reply) => {    
    const links = getLinks(request.url);

    reply.header(
      'Link',
      [
        '</fonts/gabarito/Gabarito-VariableFont.woff2>; rel=preload; as=font; crossorigin',
        ...links,
      ].join(', '),
    );

    try {
      return handler(request, reply);
    } catch (error) {
      captureException({
        error,
        extra: {
          url: request.url,
        },
        message: 'could not render request',
      });

      return replyWithErrorPage(reply, error);
    }
  });
});

but the loaded route also send link header, which overrides my value from the above.

I would expect headers such as link to be merged.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions