【发布时间】: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
和
第一个 url 是我的云功能的直接路径,后者是我的“托管”url。当我向云功能发出请求时,一切都按预期工作。但是,当我向 http://localhost:5000/users/1 发出 GET 请求时,我收到一条 404 Page Not Found 消息,但是当我向 http://localhost:5000/users 发出 GET 请求时,我收到了预期的 json 响应。
我是 Firebase 托管和云功能的新手。不知道我可能做错了什么。任何帮助是极大的赞赏。
【问题讨论】:
-
这篇帖子stackoverflow.com/questions/44959652/…为我解决了我的问题。
标签: javascript firebase google-cloud-functions firebase-hosting