This is probably a dumb question, but I can't figure out how the Firebase functions must be used.
I'm new to Firebase. I created a Firebase projet by following some tutorials. My final goal is to create dynamic websites with authentification and database. I'm very familiar with PHP, node.js, mySql... But I am a bit confused with Firebase.
My project use static pages hosting and functions. Both works, but they do no share the same URL when deploy.
I'm used to mix on the same domain static and dynamic pages. Since the functions and the hosting are not are at the same URL, I don't understand how to create dynamic pages. More generally, I'm probably missing something about the philosophy of the functions.
Can anyone enlighten me?
What you are missing is that you can redirect some URLs to functions. Add the following lines to firebase.json
:
"rewrites": [
{
"source": "/app/**",
"dynamicLinks": true,
"function": "app"
}
]
and the following to functions/index.js
:
// Create an app with Express
const express = require("express");
const app = express();
// Any URL starting with /app/id will call this function
app.get("/app/:id", (req, res) => {
res.send("ID = " + req.params.id);
});
If it is not clear, check this page. Everything you need to understand is detailed: https://lucidar.me/en/firebase/host-a-dynamic-website-on-firebase/