Skip to content

Conversation

@marshall-lee
Copy link
Contributor

Firebase wrappers such as onRequest, onCreate, etc return callable handlers with some important additional data in properties which is being used by firebase-cli while deploying the functions.

So when we wrap such functions naively, these properties are not visible anymore. So I decided to circumvent it with a new Proxy(fn, { apply: ... }) trick. This proxy object will redirect all property accesses to the original function but calling behavior will be re-defined.

Also added some workarounds for firebase emulator (firebase emulators:start)

  • Need to wrap fn.__emulator_func too. See code comments.
  • Need to create a new domain because unlike functions-framework, firebase emulator doesn't create a domain.

Fixes #3023.

Also this PR removes a dependency on @google-cloud/functions-framework package since it's used only for importing types but these types are also needed for TypeScript users and we cannot force them to install an entired functions-framework as a dependency. Instead, I moved all the types from it right in this package and also add a runtime dependency @types/express. Fixes #2997.

Firebase wrappers such as `onRequest`, `onCreate`, etc return callable
handlers with some important additional data in properties which is
being used by `firebase-cli` while deploying the functions.

So when we wrap such functions naively, these properties are not
visible anymore. So I decided to circumvent it with a
`new Proxy(fn, { apply: ... })` trick.
This proxy object will redirect all property accesses to the original
function but calling behavior will be re-defined.

Also added some workarounds for firebase emulator (`firebase
emulators:start`)

- Need to wrap `fn.__emulator_func` too. See code comments.
- Need to create a new domain because unlike `functions-framework`,
  firebase emulator doesn't create a domain.

Fixes getsentry#3023.

Also this commit removes a dependency on `@google-cloud/functions-framework` package
since it's used only for importing types but these types are also needed for TypeScript
users and we cannot force them to install an entired functions-framework
as a dependency.
Instead, I moved all the types from it right in this package and also add a
*runtime* dependency `@types/express`. Fixes getsentry#2997.
It's not enough to include it only in `devDependencies` because without
it TypeScript users are getting type errors.
@marshall-lee marshall-lee force-pushed the serverless/gcpfunction-proxy branch from 1fd8404 to 476d4c1 Compare November 10, 2020 22:54
@HazAT HazAT merged commit af2c002 into getsentry:master Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants