Я написал код в точности так, как показано в руководстве по Firebase, и он не работает - PullRequest
0 голосов
/ 25 мая 2019

Итак, вот учебник, который я смотрел: https://www.youtube.com/watch?v=LOeioOKUKI8&t=865s В основном я пытаюсь сделать локальный хостинг веб-страницы через Firebase, и он продолжает давать сбой, и это ошибка, которую я получаю на своей консоли BASH.

i  functions: Preparing to emulate functions.
i  hosting: Serving hosting files from: public
✔  hosting: Local server: http://localhost:5000
Warning: You're using Node.js v12.1.0 but the Google Cloud Functions runtime is only available in Node.js 6 (Deprecated), Node.js 8, and Node.js 10 (Beta). Therefore, results from running emulated functions may not match production behavior.
⚠  functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠  functions: Error from emulator. Error parsing triggers: Cannot find module 'consolidate'

Try running "npm install" in your functions directory before deploying.

Я выполнил установку npm в своем каталоге функций и также выполнил npm i - сохранение firebase-functions внутри моего каталога функций.

const functions = require('firebase-functions');
const firebase = require('firebase-admin');
const express = require('express');
const engines = require('consolidate');

const firebaseApp = firebase.initializeApp(
     functions.config().firebase

);

function getFacts() {
const ref = firebaseApp.database().ref('facts');
return ref.once('value').then(snap => snap.val());
}

const app = express();
app.engine('hbs', engines.handlebars);
app.set('views', './views');
app.set('view engine', 'hbs');

app.get('/', (request, response) => {
    response.set('Cache-Control', 'public, max-age=300, s- 
    maxage=600');
    getFacts().then(facts => {
    response.render('index', { facts });
});
});

exports.app = functions.https.onRequest(app);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...