Firebase call Google Cloud function issue - two functions with the same name - firebase

I've got two Google Cloud functions with the same name but in two different regions.
How do I specify which function should be called (as there are two of them with the same name)?
My firebase.json file:
{
"hosting": {
"public": "public",
"rewrites": [
{
"source": "/test",
"function": "paaspiutil"
}
]
}
}

You can current only deploy functions in us-central1 if you want to link it to hosting as referenced in a previous answer and heres the links to the docs

Related

How to create firebase dynamic links for custom domain with format example.com/<path>/<some_path>

I'm trying to create firebase dynamic link for url like: example.com/<path>/<some_path>.
example.com will only be used for dynamic links and has already been hosted on firebase.
The firebase config that I'm using is:
{
"hosting": {
"appAssociation": "AUTO",
"rewrites": [
{
"source": "/**",
"dynamicLinks": true
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
I've created some dynamic links with the associated domain from dashboard with short url example.com/b. When I open this url, it shows message "Dynamic Link Not Found". And for example.com/b/some it shows Failed to resolve uri domain prefix: https://example.com/b.
So, my questions are:
Is the config correct?
Is creating dynamic links with url format example.com/<path>/<some_path> supported? How?
Are there any workarounds on how to implement this using dynamic links or am I missing the whole point of this?

Firebase Functions multiple directories - Nuxt 3 / Nitro

I'm experimenting with Nuxt 3 on Firebase hosting and have a basic build deployed successfully. However, it has taken over the functions directory.
Is it possible to specify a second directory in firebase.json? Thanks.
Here is the relevant portion of my working-for-nuxt firebase.json file.
"functions": {
"source": ".output/server",
"runtime": "nodejs14",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
},
Nuxt 3 creates a single function ("server") and deploys to Cloud Functions. If you want to deploy functions from another source directory as well e.g. for Firestore triggers then you can pass an array to functions property in the firebase.json as shown below:
{
"functions": [
{ "source": ".output/server", "codebase": "nuxt_app" },
{
"predeploy": "npm --prefix \"$RESOURCE_DIR\" run build",
"source": "functions",
"codebase": "cloud_functions"
}
]
}
Checkout the documentation to learn more about Managing multiple source packages.
If you are not using background functions like Firestore or Cloud Storage triggers and just using HTTP callable functions, then you can use NuxtJS Server Routes to deploy HTTP endpoints.

Firebase Functions: route every URL through function and serve from "hosting"

I'm trying to get every url in a subdomain to be routed through a firebase function. This is my configuration:
The functions file:
const functions = require('firebase-functions');
exports.handleWebRequest = functions
.region('europe-west1')
.https
.onRequest((req, res) => {
res.send('Currently down.');
});
My firebase.json:
{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "handleWebRequest"
}
]
},
"functions": {
"source": "firebase-functions",
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
}
When I deploy the hosting and functions, and go to the URL in my browser, I expect to see "Currently down" for every route I open. However, every route except the root route shows the "Currently down" message, and the root route shows the index.html that I deployed.
So, in a nutshell:
/ shows my index.html (which I don't want)
/whatever shows "Currently down." (which is what I want)
The reason I'm trying to route everything through the function, is because I want to shield the website with HTTP Basic Auth, which is "not natively supported" by Firebase.
This is most probably because you still have the index.html file under the public folder.
As explained in the doc:
Note: The static files in the public directory take precedence over
the rewrites, so any static files will be served alongside the Cloud
Functions endpoints.
If you remove the index.html file it should work the way you expect.
Your function is deployed to the "europe-west1" region, but Firebase Hosting currently only supports the default "us-central1". This is stated in the documentation:
Important: Firebase Hosting supports Cloud Functions in us-central1 only.

Adding root folder outside of public to hosting Firebase

I have the following structure (to handle different theming) using different websites on Firebase.
/src
/theme-1/index.html
/theme-2/index.html
All the "juice" is within src and the file index.html is the same for both theme-1 and theme-2 with exception of the line where I refer to the .css file, where I use actually a different on.
For the moment, I only configured one target but I will add more in my firebase.json:
{
"hosting": {
"target": "theme-1",
"public": "theme-1",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{"source": "**","destination": "/theme-1/index.html"}
],
"cleanUrls": true,
"headers": [ {
"source": "**",
"headers": [ {
"key": "Cache-Control",
"value": "max-age=60"
} ]
} ]
}
}
I then configure my target using the cmd commands to point to my firebase site:
firebase target:apply hosting theme-1 theme-1
and subsequently deploy the website:
firebase deploy
However, when I visit the page (despite it working locally), it seems not to be able to find the root folder /src (404 error).
How can I also include the folder /src in my deployment such that it works in the same way?
Only the directory specified by public is deployed to Firebase. The name is slightly misleading because there are no "private" files/directories.
So you have to do "public": "src" (or "public": "." if you want to deploy the theme directories as well), and adjust the other properties accordingly.

Split firebase.json configuration into two different projects

I have a working firebase project where I have a react project + cloud functions in it and I want to move all my functions into a different project (different repository), my problem is that I'm rewriting the hosting url to map the cloud functions like this
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/fns/cohorts/*/progress",
"function": "cohortProgress"
},
{
"source": "**",
"destination": "/index.html"
}
]
}
So I'm not sure how to split this firebase.json into two. One for the functions + hosting rewrites and other for the hosting only.
My guessing is that this two files are going to override one and another instead of merging.
Another idea I had was to use git submodules to manage only one file from this two different repositories but I'm not sure
Any ideas?

Resources