我无法访问Firebase Hosting上的快速路线

问题描述 投票:0回答:1

现在我按节点服务器创建了一个文件

const functions = require("firebase-functions")
const express = require("express")

/* Express */
const app = express()
app.get("/test", (request, response) => {
  response.send("Hello from Express on Firebase!")
})

const api1 = functions.https.onRequest(app)


module.exports = {
  api1
}

firebase.json

    {
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ]
  }
}

我已经将它部署到firebase托管并尝试访问它在firebase托管index.html显示给我,但当我需要/test它返回为404.html页面!我错过了什么?

更新firebase.json并添加重写后

{
  "hosting": 
  {
    "public": "public",
    "rewrites": [
      {
          "source": "/test",
          "function": "app"
      }
    ]
  }
}

消息是不同的现在enter image description here


答案


我必须将我的项目文件结构化为-project(文件夹)---函数(文件夹)(包含在所有nodejs文件中)--- public(filder)

firebase firebase-hosting
1个回答
1
投票

您需要在firebase.json文件中包含rewrites部分。这告诉Firebase服务器如何路由任何进来的请求......现在,你没有告诉任何事情。

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

This answer实际上并不是你问题的答案,但它演示了使用云功能快递应用程序设置重写的正确方法。

© www.soinside.com 2019 - 2024. All rights reserved.