0

When I make a POST request in Chrome to my NodeJS Fastify server, Chrome's network tab displays one post request:

enter image description here

However, Fastify logs two requests each with a unique request ID:

enter image description here

Now, what is crazy is that when I perform the same request in Firefox, Fastify only logs one request... So is this a Chrome issue or a Fastify/NodeJS one?

Front-end POST request:

            const response = await fetch('/api/signupForm', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    foo: bar,
                })
            }).then(response => response.json()).catch(error => {
                ...
            });

Fastify request:

    fastify.post('/signupForm', {
        body: {
            type: 'object',
            required: ['foo'],
            properties: {
                foo: {
                    type: 'string'
                }
            }
        },
        //Output Serialization
        schema: {
            response: {
                200: {
                    type: 'object',
                    properties: {
                        success: {
                            type: 'boolean'
                        }
                    }
                }
            }
        },
    }, async (req, reply) => {
        console.log('route started..............................................................');

...
now_world
  • 940
  • 7
  • 21
  • 56
  • Switch your network tab from XHR to All so you can see it. Probably a favicon request or a cross-origin OPTIONS request that is getting routed to the wrong place in your app for some reason. – Brad Aug 28 '20 at 04:02
  • @Brad I looked and even with the network tab set to "all" there aren't any other requests that should trigger this.. It seems to also be related to how fast the request is processed by fastify, but I don't know why – now_world Aug 28 '20 at 04:15
  • @Brad ... cross origin? there's no hostname in the fetch URL, so, can't be cross origin :p can't be a favicon request - you don't get those on XHR - besides, the OP states that the SERVER logs the same request twice, nothing about favicon - it's probably a Chrome bug – Jaromanda X Aug 28 '20 at 04:15
  • 1
    @JaromandaX I try to not assume much from posts like these, when there isn't really enough information to solve it, and the person posting can just click the appropriate tab in the developer tools to get the info. :-) Sounds like they've done that now and is the issue is non-obvious. – Brad Aug 28 '20 at 04:20
  • My guess ... chrome bug ... it's full of bugs – Jaromanda X Aug 28 '20 at 04:22
  • Could you edit to add a complete example to reproduce? Because those snippet work on my chrome so I think there could be some pending async task (like hooks) - since I see 500 http response and not 400 due the validation error – Manuel Spigolon Aug 28 '20 at 05:58
  • @ManuelSpigolon I've tried creating a reproduce project, but I cannot seem to reproduce the error with the example reproduce project.The error only ever seems to happen sometimes on my main project, which is really weird. I'm just going to guess that it is some sort of bug and try to handle it another way :( – now_world Aug 28 '20 at 19:30
  • I think this smells like not a solution that could lead to memory leak and so on. – Manuel Spigolon Aug 29 '20 at 13:02

0 Answers0