I have a webpage application developed using Flutter.
I am hosting this on Firebase hosting.
There are some data which changes over a long period of time say in 2-3 days. So I am fetching this data through Firebase cloud function.
Is there any way the data sent by the cloud function get cached to cdn? The steps that i tried so far, are caching in the browser only.
Here is firebase.json
{
"hosting": {
"target": "flutter",
"public": "build/web",
"headers": [
{
"source": "**",
"headers": [
{
"key": "Cache-Control",
"value": "'public, max-age=300, s-maxage=600'"
}
]
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
},
{
"source": "/fetchData/**",
"destination": "/index.html"
}
]
}
}
and here is my cloud function
var globalData = "some global static data"
const functions = require("firebase-functions");
const cors = require("cors");
exports.fetchData = functions.https.onRequest(async (req, res) => {
var corsFn = cors();
await corsFn(req, res, async function () {
var body = req.body;
res.set("Cache-Control", "public, max-age=300, s-maxage=600");
res.status(201).send({
data: globalData,
});
});
});
with this, I am able to cache the cloud function data but only in the browser. What I want is to cache in Firebase global cdn.