0
votes

I have a project with multiple firebase hosting projects set up (for staging and production), and when I add rewrites per the Firebase docs here the rewrite for function /bigben does not work at https://customdomain.com/bigben (both deployed to production and in the emulators)

firebase.json

{
  "hosting": [
    {
      "target": "production",
      "public": "build",
      "rewrites": [
        {
          "source": "/bigben",
          "function": "bigben"
        },
        {
          "source": "**",
          "destination": "/index.html"
        },
        {
          "source": "!/@(js|css|svg|jpg|png|gif|ico|json|html)/**",
          "destination": "/index.html"
        }
      ]
      // ...
    },
    {
      "target": "staging",
      "public": "build",
      "rewrites": [
        {
          "source": "/bigben",
          "function": "bigben"
        },
        {
          "source": "**",
          "destination": "/index.html"
        },
        {
          "source": "!/@(js|css|svg|jpg|png|gif|ico|json|html)/**",
          "destination": "/index.html"
        }
      ]
      // ...
    }
  ]
}

How can I set /bigben to use this custom domain (that is already configured in Firebase for hosting/the frontend create-react-app? I've seen removing index.html from the build folder, but isn't that needed for CRA?

1

1 Answers

1
votes

I know the docs say your source should look like that, a simple path, but it never seems to work for me either. Change your source for bigben from:

"source": "/bigben",

to this:

"source": "/bigben/**",

After that it should do the rewrite correctly.

Edit:

Also your rewrites are out of order and so all of your source files are being rewritten to index.html. Here are my recommended changes:

{
  "hosting": [
    {
      "target": "production",
      "public": "build",
      "rewrites": [
        {
          "source": "/bigben/**",
          "function": "bigben"
        },
        {
          "source": "!**/*.*",
          "destination": "/index.html"
        }
      ]
      // ...
    },
    {
      "target": "staging",
      "public": "build",
      "rewrites": [
        {
          "source": "/bigben/**",
          "function": "bigben"
        },
        {
          "source": "!**/*.*",
          "destination": "/index.html"
        }
      ]
      // ...
    }
  ]
}