GunnWATT/watt

Use v2 Firebase functions

ky28059 opened this issue · 0 comments

For docs on the public preview, see the firebase docs. Upgrading to v2 would allow for easier cors configuration, but more importantly it adds support for concurrency which might save a lot on cold start times; for API especially, I'm not sure keeping one instance always warm is enough to eliminate huge startup costs on multiple requests.

The issue for WATT is that we can't adopt the gradual upgrade strategy described in the docs where v1 and v2 functions exist in the same codebase because sgyAuth and sgyFetch rely on functions.config(), a method that is removed in v2 in favor of secrets and environment variables. Updating those functions to v2 would require moving .runtimeconfig.json to .env.local like

SGY_KEY=...
SGY_SECRET=...

and rewriting sgyOAuth to use process.env.SGY_KEY and process.env.SGY_SECRET (this might require making a new instance of oauth per request due to secrets being function-scoped). However, sgyAuth and sgyFetch are all callable functions and suffer from caveats while v2 functions are in beta that require changing

const init = httpsCallable(functions, 'sgyfetch-init');

to something like

const init = httpsCallableFromURL(functions, 'https://gunnwatt-uvb3o4q2mq-uw.a.run.app/sgyfetch-init');

and because v2 function URLs are non-deterministic this URL would need to be updated every time the function is changed and redeployed.

If cold starts end up becoming a huge deal, we might want to upgrade to v2 despite these limitations, but otherwise we can wait until cloudfunctions.net URLs are supported.