[英]Unhandled rejection Error: Cannot find module 'handlebars' in firebase hosting using express
[英]Firebase Hosting can't find Express Endpoints
我已經在 Firebase 上設置了托管,並按照 Google 提供的文檔配置了我的 Node.js express 應用程序。 包括正確的文件夾結構和命令行指令來初始化 firebase 和 firebase-functions。
文件夾結構:
Project
-- functions
-- node_modules
-- index.js
-- package.json
-- public
-- index.html
-- 404.html
.firebaserc
firebase.json
我已通過以下代碼將 express 應用程序添加到 firebase 函數 http 請求中:
// Set up endpoint
app.get('/api', (req, res) => {
res.json({
message: 'Welcome to the Line Prophet API. Good luck.'
})
});
/**
* Firebase cloud functions
*/
exports.app = functions.https.onRequest(app);
我的Firebase.json文件設置為將所有請求定向到應用程序目標:
{
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**",
"destination": "app"
}
]
}
}
一旦我從我的父目錄運行firebase deploy一切都很好,它說應用程序已部署:
但是,之后我導航到https://line-prophet.web.app/api並收到 404 page not found 錯誤。
我嘗試使用firebase 服務在本地運行它,但我遇到了同樣的問題。 這是短暫的工作,這就是為什么我覺得一切都設置正確,但是在再次部署后它已經壞了。 任何提示表示贊賞。 謝謝!
最新的部署表明只有 4 個文件部署到 Firebase,這似乎非常低。 我檢查了“功能”選項卡,我確實看到“應用程序”在那里並且源代碼是正確的。
感謝@LawrenceCherone 將 firebase.json 文件更改為:
"rewrites": [
{
"source": "**",
"function": "app"
}
]
解決了我的問題。 由於在線文檔,我使用的是目的地而不是 function,但是將所有請求定向到您設置的 function 以處理 Z80791B3AE7002CB88C246876D9FAA8F8 請求更有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.