【问题标题】:invoke Cloud Function on specific paths在特定路径上调用 Cloud Function
【发布时间】:2020-05-05 21:23:21
【问题描述】:

我正在对每个请求调用一个函数。我可以从重写中排除 /test 目录吗?

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

【问题讨论】:

    标签: firebase google-cloud-functions firebase-hosting


    【解决方案1】:

    正如所写,您的规则以一种没有意义的方式重叠,因为您有两条 ** 路由。第二个(指向index.html)永远不会匹配。您可以使用否定来执行您的提议:

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

    【讨论】:

    • 我很困惑那么正确的方法是什么?只有一次重写?如何指定我希望为 /* 而不是 //test 触发函数?纯属运气,但 { "source": "**", "destination": "/index.html" } 正在使 / 不调用该函数
    • 静态内容是higher priority而不是重写,所以/匹配静态文件/index.html。我在上面给您的内容似乎可以满足您的需求-/ 将是/index.html/test/** 不会被重写为函数,其他所有内容都会。
    猜你喜欢
    • 1970-01-01
    • 2020-01-15
    • 2016-06-29
    • 2016-11-12
    • 2018-11-17
    • 2012-05-08
    • 2020-01-13
    • 1970-01-01
    • 2011-12-09
    相关资源
    最近更新 更多