My Folder structure:
-functions
-modules
-index.js
In index.js, I written only required module and the exported function name.
When I'm deploying one function from module, firebase deploying the entire modules folder in google cloud console.
Is it the normal behavior or do I've to change the folder structure ?
Related
I have a folder named "functions" on my angular project that was created by "firebase init functions" command
I use this folder to deploy functions to the cloud
I would like to know if their code is exposed to the end client through the firebase hosting?
I have a file I need to get into the Google Cloud Function's directory for a multi-step problem. Matplotlib: Custom fonts in cloud functions using Python 3.9
I'm not sure how to do it. Do I do it as a function in cloud functions? or use the console terminal for the project? I tried that and looked in the root directory and there was nothing there. I can only change projects and not change to a specific function directory.
Can someone please show me how to put this file https://www.1001freefonts.com/balthazar.font into the function's file system so it can be called during execution?
When you deploy a Cloud Function to GCP, you can supply a ZIP file or a directory that contains your source code and additional artifacts/files that you may need.
To perform the deployment of the ZIP or directory, you will want to use the gcloud command. A good article on this is Deploying from Your Local Machine.
The detailed documentation on the CLI can be found at gcloud functions deploy.
In your example, you could create a directory that contains your source and your font file and both will be present in the context of the Cloud Function. I believe that if you want to reference the files, you will want to use the local current directory in your code. For example, instead of coding /myfontfile.font you might code ./myfontfile.font.
Here are some references to this technique:
Cloud Functions: how to upload additional file for use in code?
I know the path directory is the right path, it's just that I always get the error 'Error: ENOENT: no such file or directory, stat '/public/resetp.html'
My paths are as follows:
index.js: firebase/functions/index.js
reset password.html: firebase/public/resetp.html
When I go to this endpoint on my function on my website it runs this code:
response.sendFile(path.join(__dirname, '/./public/resetp.html'));
I need to use the sendFile() function so that I can just render the html file and not change the URL since in the html file that I'm trying to load, it gets the parameters of the URL (like the action code) and gets the users input to reset the users password.
Thanks, Nathan
You can achieve this by making your public directory inside your functions directory:
{
"hosting": {"public": "functions/public"}
}
All of the files in your functions directory are deployed with Cloud Functions, and no files outside of it are available.
Warning: The files that will be available will be whatever files are in the public directory at the time you deploy Cloud Functions. It is up to you to make sure Hosting and functions deploys are kept in sync.
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:
Symbolically linking the 'server' directory
Adding a local repo to send-confirm/package.json
Neither of the above work.
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:
Any public npm repository.
Any web-visible URL.
Anywhere in the 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:
Move your 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.
Expose your code behind a URL somewhere. For example, you could package up a .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.
I want to automate creation of google docs folder via sdk. is that possible via google driver sdk or google app scripting ?
https://developers.google.com/google-apps/
The relevant docs, which describe the creation of folders, are at:
https://developers.google.com/drive/web/folder
Creating a folder uses the same request as creating a file. Assigning the correct MIME type to the file makes it act as a folder.