【发布时间】:2019-10-01 09:01:37
【问题描述】:
我是 firebase 新手,正在尝试从下面的视频中制作简单的 Cloud Functions + Express 示例。
https://www.youtube.com/watch?v=LOeioOKUKI8
当我尝试从 http://localhost:5000/timestamp 提供我的 index.js 时,我收到以下错误。
无法获取 /{my-project-id}/us-central1/app/timestamp
在我的终端中,我得到以下输出。
⚠ 创建了默认的“firebase-admin”实例!
i 函数:在 ~1 秒内完成“应用程序”
[托管] 将 /timestamp 重写为 http://localhost:5001/{my-project-id}/us-central1/app 用于本地函数应用
但如果我部署,它会按预期工作,并且会显示我的时间戳。
我当前的代码如下。
index.js
var admin = require("firebase-admin");
admin.initializeApp();
const functions = require('firebase-functions');
const express = require('express');
const app = express();
app.get('/timestamp', (request, response) => {
response.send(`${Date.now()}`);
});
exports.app = functions.https.onRequest(app);
firebase.json
{
"hosting": {
"public": "public",
"rewrites": [{
"source": "/timestamp",
"function": "app"
}],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
如果我将 index.js 的一部分重写为类似,
app.get('/{my-project-id}/us-central1/app/timestamp', (request, response) => {
response.send(`${Date.now()}`);
});
当我访问http://localhost:5000/timestamp时它会显示我的时间戳。
有人知道为什么会这样吗?
【问题讨论】:
标签: node.js firebase express google-cloud-functions firebase-hosting