【问题标题】:firebase functions - cannot GET "/"firebase 函数 - 无法获取“/”
【发布时间】:2019-02-21 08:18:07
【问题描述】:

我目前正在使用 Firebase Cloud Functions 解决方案开发服务器端渲染应用程序

为了实现这一点,我想在根 url 插入一个 express 实例(用于自定义路由)

我想用一个简单的 /<function> (/helloWordl) 重写它而不是 /<project>/<zone>/<function>(例如:/test/us-central1/helloWorld)网址

为了实现这一点,我尝试取消 url 重写 Firebase Hosting 的功能:

{
  "hosting": {
    "rewrites": [
      { 
        "source": "**",
        "function": "helloWorld"
      }
    ]
  }
}

但是现在,当我运行 firebase serve 时,我的本地服务器在我尝试的每个 url 上都会显示 404 错误

【问题讨论】:

  • 你有没有实现 helloWorld 函数来处理请求?
  • 是的,这是默认的注释路由(当您使用 fireabse-tools 设置功能时)
  • 请在此处查看我的回答:stackoverflow.com/a/54096387/4516797希望对您有所帮助

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


【解决方案1】:

官方文档“Customize Hosting Behavior”中显示的用法是重定向到文件的示例,由属性键“destination”指定

但是当您尝试将 url 重写为函数时,请改用 function

{
  "hosting": {
    "rewrites": [
      { 
        "source": "**",
        "function": "helloWorld"
      }
    ]
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 2019-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多