0

So my backend application architecture is the following:

  • Deployed Web Api microservice on cloud run (nodejs express app)
  • Configured API Gateway for token validation from client (mobile app)

Profile pictures are saved to a bucket and different users access those pictures.

I would like to implement caching as the read quotas on free tier of 1GB per day is low.

I have read about Firebase Hosting that uses CDN but i can not seem to find a way to use it without building a form of a SPA page .html or other relative static contents that refers to a front end web application.

Another way that i read here: Getting started with HTTP(S) Load Balancing for API Gateway is to create a load balancer but i just want to run a small POC for my project with minimum costs, meaning that my app is not multi region yet and i don't have an established domain.

Is there a way to use the Firebase Hosting CDN for my setup? Any other thoughts for this setup?

Thanks in advance

kostasandre
  • 63
  • 1
  • 1
  • 7

2 Answers2

0

While Firebase Hosting has an API that you can use to deploy files, the most common approach is to upload files to it by running firebase deploy on your development machine. It is therefor best suited for hosting resources that you know when you build the app - and not ideal for user generated content, such as profile pictures.

Recommending services is off-topic on Stack Overflow, but a search for free image hosting API is probably a good place to start.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

ok so after a lot of research i ended up creating a cloud function which fetch the data from storage and sets on response headers the cache control key. So on the firebase.json on the hosting configuration i created a rewrite rule to my cloud function. Now successfully the CDN works! firebase.json:

"hosting": {
    "rewrites": [
      {
        "source": "/api/getPicture",
        "function": "getPicture",
        "region": "europe-west1"
      }
    ],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }

And the response headers of my cloud func:

response.set("Cache-Control", `public, max-age=${cacheMaxAge}`);

Unfortunately, it seems that i cannot somehow validate a bearer token in Firebase Hosting. Any other workarounds would be nice to be posted.

kostasandre
  • 63
  • 1
  • 1
  • 7