【问题标题】:Cannot have nested routes in firebase cloud function不能有火力点云功能嵌套路线
【发布时间】:2019-06-27 05:10:00
【问题描述】:

我正在尝试实现 firebase 托管重写。这是我的 firebase.json

{
  "functions": {},
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "/users",
        "function": "usersMicroservice"
      }
    ],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

我的函数/index.js 文件看起来像这样

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

const app = express();

app.get("/users", (req, res) => res.json({message: "hello world"}));
app.get("/users/next", (req, res) => res.json({message: "hello world 2"})));


exports.usersMicroservice = functions.https.onRequest(app);

我在本地运行我的服务器。日志中显示了两个 url。他们是

http://localhost:5001/test-development/us-central1/usersMicroservice

http://localhost:5000

第一个 url 是我的云功能的直接路径,后者是我的“托管”url。当我向云功能发出请求时,一切都按预期工作。但是,当我向 http://localhost:5000/users/1 发出 GET 请求时,我收到一条 404 Page Not Found 消息,但是当我向 http://localhost:5000/users 发出 GET 请求时,我收到了预期的 json 响应。

我是 Firebase 托管和云功能的新手。不知道我可能做错了什么。任何帮助是极大的赞赏。

【问题讨论】:

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


【解决方案1】:

试试这个:

app.get("/users/:next", (req, res) => res.json({message: "hello world 2 " + req.params.next })));

【讨论】:

  • 嘿克里斯。刚才能够测试您的建议。我得到同样的 404 错误。
猜你喜欢
  • 2018-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 2018-04-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多