GoogleCloudPlatform / functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
Apache License 2.0
1.29k stars 158 forks source link

request `body` is undefined in production #533

Closed punksta closed 1 year ago

punksta commented 1 year ago

My function doesn't parse json body in production, but works in local environment.

import * as ff from '@google-cloud/functions-framework';

ff.http('localTesting', (req: ff.Request, res: ff.Response) => {
     res.json({
                "message": "Hello from a lambda function!",
                requestBody: req.body,
                params: req.params,
                query: req.query
            })
})

output:

{
    "message": "Hello from a lambda function!",
    "requestBody": {},
    "params": {
        "0": ""
    },
    "query": {}
}

This is how I call the function

curl --request POST \
  --url http://nodejs-http-function-XXX.run.app/ \
  --header 'Accept: application/json' \
  --header 'content-type: application/json' \
  --data '{
    "hello": "world"
}'

Deployment script:

gcloud functions deploy nodejs-http-function \
--gen2 \
--runtime=nodejs18 \
--region=europe-west1 \
--source=. \
--entry-point=localTesting \
--trigger-http \
--allow-unauthenticated

I have searched internet for 1h and couldn't found anything helpful, google cloud examples are not helpful enough too. It's annoying.

garethgeorge commented 1 year ago

Sorry you're running into an issue here.

To help you look into your missing contents, are you able to find any logs on Google Cloud for your function invocation (guide for finding logs)?

If you drill down into the log for the function's invocation you should be able to see the request size, method, and other properties? Try looking for that log and sharing it here. I'm interested to see if it looks like the function is receiving your body and that the properties of the request are correct.

punksta commented 1 year ago

I have migrated to Azure. I am sorry.