Combining React router and Firebase function api

Viewed 149

i would like to know if there is a way to use both react-router-dom and firebase functions. For example the React part has a few links like mywebsite.com/pageone, mywebsite.com/pagetwo, mywebsite.com/pagethree. I want to add a mywebsite.com/api link that comes from a firebase function. I looked up the firebase documentation but it only shows to do either one or the other. Is this possible? Here is the firebase.json

{
  "hosting": {
    "public": "build",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      },
      {
        "source": "/app/api",
        "function": "app"
      }
    ]
  }
}
1 Answers

Try changing the order of the rewrites so the wildcard is at the end. That solved it for me.

From:

"rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      },
      {
        "source": "/app/api",
        "function": "app"
      }
    ]

To:

"rewrites": [
      {
        "source": "/app/api",
        "function": "app"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
Related