Search code examples
firebasegoogle-cloud-functionsfirebase-hosting

Firebase base hosting rewrite rules to function - "Cannot GET"/"Cannot POST"


So, I have a test cloud function (I assume posting this is safe):

curl https://image-qypxcq7f4q-uc.a.run.app -u test@example.com:Test2Test

That returns "Hello ${user ID}"

I added following rewrite rules:

    "rewrites": [
      {
        "source": "/api/v1/image",
        "function": "image",
        "region": "us-central1"
      },
      {
        "source": "/api/v1/image/**",
        "function": "image",
        "region": "us-central1"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]

Opening https://shotty.dev/api/v1/image shows "Missing Authorization header" - thus I know it hits my endpoint.

curl https://shotty.dev/api/v1/image -u test@example.com:Test2Test

shows:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /api/v1/image</pre>
</body>
</html>

Logs do not show my function body being invoked. Sometimes even https://image-qypxcq7f4q-uc.a.run.app stops responding.

Is this some quota or anti-abuse? Is this cache?


Solution

  • My function is Express (to make it easier to handle post/get/etc and have route parameters).

    Turns out, the request was sent to: https://image-qypxcq7f4q-uc.a.run.app /api/v1/image and not the function root. Express was rejecting this path.