I have a Node server and multiple controllers that perform DB operations and helpers (For e-mail, for example) within that directory.
I'd like to use source from that directory within my functions. Assuming the following directory structure:
src/
server/
/app/controllers/email_helper.js
fns/
send-confirm/
What's the best way to use email_helper
within the send-confirm function?
I've tried:
Neither of the above work.
Access control for users Cloud Functions supports the basic roles of Editor, Owner, and Viewer, which give the following permissions: Editor and Owner: Read and write access to all functions-related resources. Lets users deploy, update, and delete functions. Additional access to other resources in the project.
Cloud Functions current supports the Node. js 8 JavaScript Runtime, and the Node. js 10 Engine is in beta. You can choose a Node version it from your package.
Click Security to open the security tab. Click Reference a secret to set a secret for the function. Select the secret to make accessible. If you need to create a secret, see Creating and accessing secrets.
onRequest creates a standard API endpoint, and you'll use whatever methods your client-side code normally uses to make. HTTP requests to interact with them. onCall creates a callable. Once you get used to them, onCall is less effort to write, but you don't have all the flexibility you might be used to.
In principle, your Cloud Functions can use any other Node.js module, the same way any standard Node.js server would. However, since Cloud Functions needs to build your module in the cloud, it needs to be able to locate those dependency modules from the cloud. This is where the issue lies.
Cloud Functions can load modules from any one of these places:
functions/
directory that firebase init
generates for you, and which gets uploaded on firebase deploy
.In your case, from the perspective of functions/package.json
, the ../server/
directory doesn't fall under any of those categories, and so Cloud Functions can't use your module. Unfortunately, firebase deploy
doesn't follow symlinks, which is why that solution doesn't work.
I see two possible immediate fixes:
server/
directory to be under functions/
. I realize this isn't the prettiest directory layout, but it's the easiest fix while hacking. In functions/package.json
you can then have a local dependency on ./server
..tar
and put that on Google Drive, or on Firebase Cloud Storage. Alternatively, you can use a public git repository.In the future, I'd love it if firebase deploy
followed symlinks. I've filed a feature request for that in Firebase's internal bug tracker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With