Skip to content

Firebase integration: Fastify remains stuck due request with application/json #6370

@alexandercerutti

Description

@alexandercerutti

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

We have deployed our backend based on Firebase function, as described in the guide on the site.

However, yesterday we found out that we didn't follow the next part, the one about adding a custom contentTypeParser, which we considered it to be optional as everything looked to be working perfectly fine without it.

We found it was not optional in the hard way: when the Content-Type: "application/json" was provided, the application became completely unresponsive, stuck.

When debugging it through the Chrome Node inspector, the console was accepting commands and everything, but it couldn't accept new http requests. No errors, no logs.

// This is how we are creating the instance, very simple
const fastify = Fastify({
	logger: true,
});

This happened both on Google Cloud and with the local Firebase emulator (with the effect that killing the emulator with CTRL+C, was keeping all the ports busy, so we had to kill them manually).

When the request was not provided with the Content-Type header at all, the application kept working fine.

This behavior sounds very odd, and it is not described neither in the guide or in the attached resources, so I was wondering if it was the case of adding some description on the guide (I may do that) or if the team expects to there be a some kind of error to be fired.

The Typescript problem

Then, there's another issue related to this: body does not exist on payload (which is an http.IncomingMessage).
The used Node types are from Node 24.3.0.

So, we could use a @ts-ignore, but that's ugly.

fastify.addContentTypeParser('application/json', {}, (_req, payload, done) => {
	// @ts-ignore
	done(null, payload.body);
});

So I'm asking if this is an issue with node typings, if body is something that is getting added by Fastify or what - if you know better.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions