我将Firebase功能host
设置为在用户访问Firebase托管URL时运行,但是没有任何记录(该功能未被触发)
index.js
:
exports.host = functions.https.onRequest((req, res) => {
console.log(">>>> FUNCTION TRIGGERED!")
res.send(">>>> GOT IT")
})
我在firebase.json
中进行了设置:
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/**",
"destination": "/index.html",
"function": "host"
}
]
}
}
这是我在本地运行时的仿真器功能日志(仿真器在localhost:4001
上运行,而Web应用程序在localhost:5000
上运行。当我访问localhost:5000
时,没有任何日志记录,即使据说该函数已初始化。
12:53:42W
ui
Emulator UI unable to start on port 4000, starting on 4001 instead.
12:53:42I
ui
Emulator UI logging to ui-debug.log
12:53:43I
functions
Watching "**firebase-project**/functions" for Cloud Functions...
12:53:43I
functions
http function initialized (http://localhost:5001/****/us-central1/host).
12:53:43I
┌───────────────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! View status and logs at http://localhost:4001 │
└───────────────────────────────────────────────────────────────────────┘
┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4001/functions │
├───────────┼────────────────┼─────────────────────────────────┤
│ Hosting │ localhost:5000 │ n/a │
└───────────┴────────────────┴─────────────────────────────────┘
Other reserved ports: 4400, 4500
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET / HTTP/1.1" 200 2603 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /static/css/main.0fec40ca.chunk.css HTTP/1.1" 200 53148 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /static/css/2.85b71462.chunk.css HTTP/1.1" 200 43004 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /static/js/main.3cf6a16f.chunk.js HTTP/1.1" 200 216613 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /static/js/2.8f67d3af.chunk.js HTTP/1.1" 200 3343005 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /faceapi/weights/ssd_mobilenetv1_model-weights_manifest.json HTTP/1.1" 200 26548 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /faceapi/weights/face_landmark_68_model-weights_manifest.json HTTP/1.1" 200 7889 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /static/media/Create%20visuals%20for%20remote%20teaching..9fdce83b.png HTTP/1.1" 200 30230 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /static/media/homepage_background.1c84776f.png HTTP/1.1" 200 72508 "http://localhost:5000/static/css/main.0fec40ca.chunk.css" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /static/media/homepage_laptop.a18abdeb.png HTTP/1.1" 200 6106290 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /faceapi/weights/face_landmark_68_model-shard1 HTTP/1.1" 200 356840 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /faceapi/weights/ssd_mobilenetv1_model-shard2 HTTP/1.1" 200 1422653 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
12:54:19I
hosting
127.0.0.1 - - [03/Nov/2020:04:54:19 +0000] "GET /faceapi/weights/ssd_mobilenetv1_model-shard1 HTTP/1.1" 200 4194304 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
这是设置功能的正确方法吗?这是我第一次与他们合作,所以我很难调试它。在某些情况下,我试图根据URL动态修改OpenGraph元标记,而我正在遵循本教程:https://medium.com/@jalalio/dynamic-og-tags-in-your-statically-firebase-hosted-polymer-app-476f18428b8b
答案 0 :(得分:1)
您的主机重写看起来不正确。我建议您查看有关如何configure a rewrite to a function的文档。它不应该有“目标”,而应该只有“源”和“功能”。另外,如果您打算通过该函数提供URI“ /”,则公用文件夹中根本不应存在index.html,否则它将首先提供。