so I ‘m experimenting with Firebase hosting and Google Cloud Run for a web lotion .
I got a static SPA deploy on firebase host, and a rewrite principle to direct all requests starting with /api to my Google Cloud Run serve .
My firebase.json file looks like this :

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**/api/**",
        "run": {
          "serviceId": "myservice-api",  
          "region": "europe-west1"     
        }
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

At inaugural, it seemed like everything worked as expected, all /api requests were handled by my Google Cloud Run service. however I started to notice foreign demeanor for some of the requests, as the reply returned by the server was not at all what I expected. Looking into it a bit far I noticed that those requests were not showing up in the logarithm of my Cloud Run military service.

indeed I checked the response headers received by the browser, and noticed that the reception was coming from Firebase cache alternatively of the Cloud Run serve :

accept-ranges: bytes
access-control-allow-origin: *
content-length: 245
content-type: application/json
date: Wed, 06 Nov 2019 11:24:32 GMT
server: Google Frontend
status: 200
vary: x-fh-requested-host, accept-encoding
x-cache: HIT
x-cache-hits: 5
x-served-by: cache-cdg20776-CDG

The documentation states :

however, because Cloud Functions and Cloud Run services beget content dynamically, the content for a given URL can vary based on such things as exploiter input signal or the exploiter ‘s identity. To account for this, requests that are handled by backend code do not cache on the CDN by default option.

So I would expect none of the requests going to /api to be cached, ever. Is there something improper in the way I defined my rewrite rules or should I consider this as an offspring in the room Firebase Hosting handles Cloud Run routing ?
UPDATE

hera is the customer request in details as shown in Chrome dev tools :

Request URL: https://myproject.web.app/api/users/me
Request Method: GET

Headers:
:authority: myproject.web.app
:method: GET
:path: /api/users/me
:scheme: https
accept: application/json;charset=UTF-8
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9,fr;q=0.8
authorization: Bearer xxx
cookie: G_ENABLED_IDPS=google; G_AUTHUSER_H=0
referer: https://myproject.web.app/auth/login/
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36

The request returns JSON data, here are the reply headers returned by the backend when actually handled by Cloud Run :

content-type: application/json
access-control-allow-origin: *
X-Cloud-Trace-Context: eeb4c0dbd22dd46f3c42fbe0b85b6420;o=1
Date: Wed, 06 Nov 2019 11:24:26 GMT
Server: Google Frontend
Content-Length: 240

therefore there is no specific header set by the server argue that the reaction should be cached .

Leave a Reply

Your email address will not be published.