2

I need to serve dynamic content by using path parameters to fetch an id from the URL when hosting on firebase. For example:

mydomain.com/apps/4480023

In this scenario, I'd like to extract 4480023 as the ID of the resource I'm looking for. I tried the following changes in the firebase.json file:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      },
      {
        "source": "/apps/**",
        "destination": "/apps.html"
      }
    ],
    "cleanUrls": true
  }
}

In which case, I can use a javascript function to retrieve the ID from the URL when the user browses to that resource. My problem is, this rewrite doesn't work and it directs the user to the index.html page and all the CSS/JS files end up not functioning correctly.

How can I modify this to enable this functionality?

2
  • can you share the code how to extract param after sorting the firebase.json Commented Jan 16, 2020 at 8:07
  • @Hanzala do you mean query param? Like: website.com?user=2 Commented Jan 16, 2020 at 23:11

1 Answer 1

5

The rewrites are checked in order. This means your first rewrite, which matches all requests, is always going to be served by index.html.

All you have to do is change the order of the rewrites to allow /apps/** to have a possibility of matching before /** captures everything else.

"rewrites": [
  {
    "source": "/apps/**",
    "destination": "/apps.html"
  },
  {
    "source": "**",
    "destination": "/index.html"
  }
]
Sign up to request clarification or add additional context in comments.

1 Comment

Didn't think that would cause this issue. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.