David in his repo:
https://github.com/davideast/react-ssr-firebase-hosting
has the file with firebase functions index.js
in the main root, not in the /functions
directory.
However, if I do the same and drop my index.js
file to main root, if I do firebase deploy --only functions
it says in the console:
i deploying functions
Error: functions\index.js does not exist, can't deploy Firebase Functions
Q: How is it possible that he made it work? How can I do the same and deploy successfully functions from other dir than /functions
?
Thanks
firebase.json
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "ssrapp"
}
]
},
"functions": {
"source": "/"
}
}
In the Source code field, select ZIP from Cloud Storage. In the Cloud Storage location field, click Browse to select a ZIP file from Cloud Storage. Your function source files must be located at the root of the ZIP file - see Source directory structure. Click Deploy.
Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment.
The project workspace that you create with the Firebase CLI contains a file called firebase.json that has a stanza for Cloud Functions that looks like this:
"functions": {
"predeploy": [
"npm --prefix $RESOURCE_DIR run lint"
],
"source": "functions"
}
That "source" property defines the name of the folder that contains the code that will run on Cloud Functions. You can change that to whatever you want.
If you want to use your root directory as your functions folder just change your source
key to .
in your firebase.json
.
"functions": {
"source": ".",
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
This will look for your index.js
file in the root directory (remember to move all the other files to your root directory too).
Documentation: https://firebase.google.com/docs/functions/manage-functions#deploy_functions
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