设置路由到多种功能

时间:2018-08-24 22:28:30

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

我有两个功能,部署在一个firebase项目中。我想实现的是根据URL路径启动不同的代码:

  • www.myApp.com / **-应该路由到function2
  • www.myApp.com/path1-应该路由到function1
  • www.myApp.com/path2-应该路由到function1

这是我的示例配置

{
  "hosting": {
    "public": "functions/dist",
    "rewrites":[
      {
        "source": "/path1/**",
        "destination": "function1"
      },
      {
        "source": "/path2/**",
        "destination": "function1"
      },
      {
        "source": "**",
        "function": "function2"
      }
    ]
  }
}

不幸的是,所有内容都路由到function2。我应该如何更改我的配置?

1 个答案:

答案 0 :(得分:-1)

尝试下面的代码。

rewrites =函数, 重新定向=目的地

 {
  "hosting": {
    "public": "functions/dist",
  "redirects": [ {
        "source": "/path1/**",
        "destination": "function1"
     }, {
        "source": "/path2/**",
        "destination": "function1"
     } ],
  "rewrites":[
      {
        "source": "**",
        "function": "function2"
      }
    ]
  }
}

引用:https://firebase.google.com/docs/hosting/url-redirects-rewrites