I have my firebase cloud functions created with region: asia-northeast1, I am trying to trigger one of the functions using the firebase.json file.
"hosting": [
{
"target": "ksite",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{ "source": "**", "function": "ssr" }
]
}
]
Unfortunately this triggers the function with region of us-central1 https://us-central1-site.cloudfunctions.net/ssr/ instead of asia-northeast1 something like this https://asia-northeast1-site.cloudfunctions.net/ssr/
How and why is this happening?
Here is my function:
// For Universal Rendering
export const ssr = functions.region('asia-northeast1').https.onRequest((request, response) => {
require(`${process.cwd()}/dist/ksite-webpack/server`).app(request, response);
});
Firebase Hosting currently only supports the proxy of URLs to functions deployed to us-central1, as mentioned in the documentation:
Important: Firebase Hosting supports Cloud Functions in us-central1 only.
And also here in the docs:
Important: If you are using HTTP functions to serve dynamic content for Firebase Hosting, you must use us-central1.
Related
Im testing go gen2 google cloud functions, the code of the function was deployed ok, it works ok, everything is fine. The function is named readrequest, and it is open to everybody. You can reach it https://readrequest-v7disnxdea-uc.a.run.app
I also add mapping to a dedicated subdomain without problem.
Now I'm trying to route in one web firebase app. For that I've added a route to firebase.json
the rules in firebase.json looks like:
{
"hosting": {
"public": "public",
"rewrites": [
{
"source": "/l",
"function": "l3"
},
{
"source": "/gotest",
"function": "readrequest"
},
{
"source": "/gotest/**",
"function": "readrequest"
},
{
"source": "/rc1",
"function": "rc1"
},
{
"source": "/rc2",
"function": "rc2"
},
{
"source": "/rc2/**",
"function": "rc2"
},
{
"source": "/rc1/**",
"function": "rc1"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
I can reach the funcion, always ask for authentication, but it doesn't work even if I accept to authenticate. I've created the function in us-central1 to avoid problems.
The error is:
Error: Forbidden
Your client does not have permission to get URL /readrequest/gotest/asdf from this server.
If I misspell the function name I get the same error, so it is like the router isn't locating the function, but don't why not.
Because Cloud Functions gen2 runs on top of Cloud Run (url, permission, logs, and many other things are the same!), the way to reach Cloud Functions gen2 is not the usual Cloud Functions gen1 manner, it's the Cloud Run one!
Buy the way, replace the function (gen1) reference "function": "readrequest", the functions (gen2, i.e. Cloud Run) reference "run": { "serviceId": "readrequest", "region": "us-central1" }
I have 2 subdomains configurated on firebase, myapp1.mydomain.cl and myapp2.mydomain.cl.
My default site url provided by Firebase are mydomain-1100.web.app
Im trying to deploy myapp1 into a subdomain with the following command
firebase target:apply hosting myapp1 myapp1.mydomain-1100
firebase deploy --only hosting:myapp1
When i do that, cli throw me the next error Error: HTTP Error: 404, Requested entity was not found.
This is my firebase.json
{
"hosting": {
"target": "myapp1",
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
What i'm doing wrong? i search for hours and i dont found a solution for my case,
i really appreciate constructive answers.
I have a NextJS app and an express.js API both hosted in Firebase Cloud Functions.
This is my firebase.json
{
"hosting": {
"public": "src/public",
"rewrites": [
{
"source": "/user",
"function": "api"
},
{
"source": "/users",
"function": "api"
},
{
"source": "**/**",
"function": "next"
}
]
},
"functions": {
"source": "src/functions"
}
}
What I expecting was to rewrite /user and /users to api Cloud Function and all other URL to next Cloud Function. But it not working as I expected. Every URL is passing to next Cloud Function even /user and /users.
And I need help...
Try the below code, you can find its used on an example of the documentation that is intended for requests to files or directories that do not exist, including all other replies I understand
// Serves index.html for requests to files or directories that do not exist
"source": "**",
"function": "next"
I am building a static website with HTML, CSS & JS and hosted on firebase hosting and connected a custom domain. The only serverside function I need is to send mail from the contact form. For this, I am trying to use Firebase cloud function. I have initialized functions on the same project and trying to use firebase hosting rewrites to rewrite the request to mydomain.com/contact to the contact function. But when I try to access the mydomain.com/contact in the browser it shows the below 403 Forbidden error message.
Error: Forbidden
Your client does not have permission to get URL /contact/contact from this server.
firebase.json
{
"hosting": {
"public": "build",
"rewrites": [{
"source": "/contact",
"function": "contact"
}],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
}
The cloud function (not implemented the actual logic)
import * as functions from 'firebase-functions';
exports.contact = functions.https.onRequest((request, response) => {
response.send("<h1>Contact<h1>");
});
I am using Firebase spark plan.
This works for me:
"rewrites": [
{
"source": "**",
"function": "myApp"
}
]
And in the express function,
import * as functions from 'firebase-functions';
import express from 'express';
const app = express();
app.get('/contact', (req, res) => {
res.send("<h1>Contact<h1>");
};
export const myApp = functions.https.onRequest(app);
I had the same issue this week. I had a rewrite from /user to a function called user and I was getting the response Your client does not have permission to get URL /user/user from this server.
I just deleted the functions from the firebase console then deployed them again and now they work. There must be some occasional bug with deploying functions like this and/or using hosting rewrites where the rewrite path gets appended to the function url path on the server.
I'm having this view on my webpage. It says, it was successfully deployed but it's not showing my SPA.
config:
"hosting": {
"public": "dist/spa-mat",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
Im using default router.js setup
{
path: '/',
component: () => import('layouts/default'),
children: [
{ path: '', component: () => import('pages/index') }
]
}
Steps taken:
(firebase already installed an im already logged in)
1. quasar build - to build quasar app for prod
2. firebase init
- `dist/spa-mat` as directory
3. firebase deploy
Any Quasar dev who has an idea how to deploy in Firebase hosting? I think I did everything right but my SPA is not showing.
Follow the official docs for Deployment of SPA in Quasar. There's a guide there how to deploy in Heroko, Now, etc.
If you're doing it right, give it several minutes to an hour.