Search code examples
firebasegoogle-cloud-functionsfirebase-hosting

invoke Cloud Function on specific paths


I'm invoking a function on every request. can I exclude the /test directory from the rewrite?

{
   "hosting":{
      "public":"build",
      "ignore":[
         "firebase.json",
         "**/.*",
         "**/node_modules/**"
      ],
      "rewrites":[
         {
            "source":"/**",
            "function":"helloWorld"
         },
         {
            "source":"**",
            "destination":"/index.html"
         }
      ]
   },
   "functions":{
      "predeploy":[
         "npm --prefix \"$RESOURCE_DIR\" run lint"
      ]
   }
}

Solution

  • As written, your rules are overlapping in a way that doesn't make sense since you have two ** routes. The second one (pointing to index.html) will never be matched. You can use a negation to do what you're proposing:

    {
      "rewrites": [
        {"source": "!{/test/**}", "function": "helloWorld"}
      ]
    }