Я создал экспресс-приложение, и структура папок ниже.
![as follows](https://i.stack.imgur.com/FERTN.png)
Затем я создал хостинг firebase init на фиктивной папке и скопировалФайлы firebase.json и .firebase
Я создал index.js file
const functions = require('firebase-functions')
const app = require('./app');
exports.widgets = functions.https.onRequest(app);
firebase.json
{
"hosting": {
"public": "public",
"rewrite":[{
"source": "**",
"function": "widgets"
}],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
Также скопировал созданный firebase файл index.html в общую папку
![enter image description here](https://i.stack.imgur.com/iQfio.png)
При развертывании я получаю index.html
![enter image description here](https://i.stack.imgur.com/vampF.png)
Если я удаляю index.html и работаю как локальный хост, я получаю значение ниже
![enter image description here](https://i.stack.imgur.com/VQuPa.png)
Как я могу запустить приложение express (как показано в localhost) вместо index.html при развертывании firebase.
Редактировать 1
Я перехожу по ссылке .
Когда я запускаю firebase serve , я получаю эту ошибку
AssertionError [ERR_ASSERTION]: missing path at Module.require (module.js:583:3) at require (internal/module.js:11:18) at InitializeFirebaseAdminStubs (C:\Users\alaksandarjesus\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:231:18) at C:\Users\alaksandarjesus\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:451:9 at Generator.next () at C:\Users\alaksandarjesus\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71 at new Promise () at __awaiter (C:\Users\alaksandarjesus\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12) at main (C:\Users\alaksandarjesus\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:421:12) at Object. (C:\Users\alaksandarjesus\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:511:5)
Когда я пытался запустить развертывание firebase
E:\ogst-server-firebase\functions>firebase deploy
=== Deploying to 'ogst-server-95fcc'...
i deploying functions, hosting
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
Error: An unexpected error has occurred.
Причиной этого является миОбщая папка ssing, и я создал ее вручную (которая должна была быть создана с помощью функций инициализации firebase).
E:\ogst-server-firebase\functions>firebase deploy
=== Deploying to 'ogst-server-95fcc'...
i deploying functions, hosting
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i hosting[ogst-server-95fcc]: beginning deploy...
i hosting[ogst-server-95fcc]: found 0 files in public
+ hosting[ogst-server-95fcc]: file upload complete
i hosting[ogst-server-95fcc]: finalizing version...
+ hosting[ogst-server-95fcc]: version finalized
i hosting[ogst-server-95fcc]: releasing new version...
+ hosting[ogst-server-95fcc]: release complete
+ Deploy complete!
Please note that it can take up to 30 seconds for your updated functions to propagate.
Project Console: https://console.firebase.google.com/project/ogst-server-95fcc/overview
Hosting URL: https://ogst-server-95fcc.firebaseapp.com
Теперь мое развертывание прошло успешно.Но я получаю 404
Ответ В файле index.js (по ссылке выше) я не изменился
module.exports = functions.https.onRequest(app); //wrong
to
exports.app = functions.https.onRequest(app); //correct
Спасибо всем за поддержку