0

We are trying to build a REST api using firebase functions. We want that format because we are a web services company who need to expose an api to our clients. People are mostly familiar with REST, therefore, REST.

Following the advice given here I have layered a custom domain in front of a firebase function. I did this by first forwarding my custom domain to the firebase domain via an A record,then setting up a rewrite for the hosting:

  "hosting": {
"public": "public",
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"rewrites": [
  {
    "source": "/api/**",
    "function": "api"
  },
  {
    "source": "!/@(api)/**",
    "destination": "/index.html"
  }
]
},

Note that the api function is mapped to anything going to /api/. So far so good. Now I want to make a POST request with a body to mydomain.com/api/user. Unfortunately, when doing so, I get a response Cannot GET /api/user. It seems like firebase is converting the request into a GET before it reaches the function at api. Does anyone know how to make POST requests to functions behind custom domains?

melchoir55
  • 6,842
  • 7
  • 60
  • 106

1 Answers1

3

In case someone stumbles over this it's because our route was not defined as containing api. We had something like /user but this configuration obviously requires /api/user.

melchoir55
  • 6,842
  • 7
  • 60
  • 106