我正在努力理解firebase.json重定向規則是如何作業的。
在這里,我定義了hosting我的網站,它完美地指向dist/project-name目錄。
"hosting": [
{
"target": "project-name",
"public": "dist/project-name",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
...
...
但是,當我嘗試實作重定向規則時,事情開始變得混亂。假設我希望將對不存在的檔案和目錄的請求重定向到我的托管公共目標。我認為這是定義它的正確方法:
"rewrites": [
{
"source": "**",
"destination": "dist/project-name"
}
]
localhost:5000/abcdef但是向像,這樣的隨機端點發出請求localhost:5000/testing并沒有被重定向,因此請求失敗。那應該source是什么?
現在,假設我不想重定向到我的公共目標目錄,而是想用 Express 重定向到 firebase 函式。
"rewrites": [
{
"source": "**",
"destination": "app"
}
]
好吧,這在模擬器 localhost:5000 中也不起作用。即使我可以在模擬器 localhost:5001 中看到功能正常作業(Express 應用程式)
我在想,因為/functions目錄不是dist檔案夾的一部分。但是為什么重定向到dist/project-name也不起作用?有任何想法嗎?謝謝!
uj5u.com熱心網友回復:
好吧,我不得不嘗試一些事情并閱讀檔案以了解我在做什么。
檔案:
- https://firebase.google.com/docs/hosting/functions#use_a_web_framework
- https://firebase.google.com/docs/hosting/full-config#rewrites
首先,我在想,通過在"destination": "dist/project-name"中進行操作rewrites,url總是會重定向到托管站點。所以無論我去什么路徑(即/abc)它都會向我展示index.html檔案。好吧,事實并非如此。重寫甚至沒有發生,我可以在日志中看到http://localhost:4002/logs。我認為這是因為優先順序。
其次,我的 Express.js 應用程式部署為 firebase 中的一個函式。"function": "app"不應該對 Cloud Functions 進行重寫"destination": "app"。
最后但同樣重要的是,我的帶有 Express.js 的云函式被部署為us-east1這樣exports.app = functions.region("us-central1").https.onRequest(app);。但是,在這里我們可以看到 Firebase Hosting 目前只接受us-central1Cloud Functions。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/456748.html
標籤:节点.js 火力基地 表示 谷歌云功能 firebase 托管
