googlearchive / cloud-functions-emulator

A local emulator for deploying, running, and debugging Google Cloud Functions.
https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki
Apache License 2.0
827 stars 115 forks source link

rawBody not present #167

Open supermacro opened 7 years ago

supermacro commented 7 years ago

Environment details

Steps to reproduce

  1. Make a request, access a non-existent req.rawBody

Notes

I am sending PUT requests with Content-Type set to multipart/form-data to have the cloud function process files and then upload them to google cloud storage.

I am using multer to parse the request and provide a .files object on req.

req.files is an object whose keys are the various form keys.

Local Behaviour

The cloud function works as intended. req.files is populated with an object that I then process and stream its contents to google cloud storate.

However, req.rawBody does not exist (not that it's an issue in this case).

Remote behavior

The cloud function does not work as intended. req.files is not populated with any data (in this case, it is an empty object) and the server crashes.

side note, runtime errors are getting swallowed both remotely and locally despite me handling the errors correctly. Hence I have basically no information to work off of when things go wrong.

In the remote case, req.rawBody is indeed a node Buffer object as the documentation states.

Conclusion

I guess there are two takeaways:

1 - rawBody should exist in local development to better mirror the true behavior of hosted cloud functions

2 - multer should work remotely assuming that req isn't being mutated to such a point as to prevent multer from doing its job of parsing multipart requests. I know this might be out of scope from this repo but it is still something to be aware of. From my understanding, all npm modules should work with GCF.

supermacro commented 7 years ago

This is a duplicate of #161, but provides further info.

n0wak commented 6 years ago

Have you been able to work around the issue? I've run into the same thing (using a similar setup) and can't get a function that works 100% in the emulator to work after deployment which is very frustrating.

supermacro commented 6 years ago

@n0wak Our team decided it wasn't worth the hassle. Not sure why google thought it was a good idea to parse the body of a request (as though us node devs didn't know how to do that ourselves) before turning over control of the request to the cloud function.

We just spun up a compute instance. IMO functions as a service come with a lot of complications and it's not worth it other than to save a substantial amount of money when running a large scale operation.

mikeknapp commented 6 years ago

fwiw, I got around this by following G. Rodriguez's instructions here: https://stackoverflow.com/a/47603055

ShaMan123 commented 6 years ago

This SHOULD be properly documented + commited to the local emulator. Took me a few days to get around this. It's a shame I didn't see this issue until now.