http returns 使用 Firebase 托管和函数 node.js 时出现内部服务器错误

http returns internal server error while using Firebase hosting and functions with node.js

我从 Firebase 托管和功能 node.js 收到内部服务器错误。我正在学习本教程并确保我的代码与他的代码完全相同:https://www.youtube.com/watch?v=LOeioOKUKI8&t=1s&pbjreload=101 我什至有一个对事实的数据库引用。

这是我的 index.js 文件:

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);

这是我的 index.hbs 文件:

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>true facts.</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h1>true facts.</h1>

    <ul>
        {{#each facts}}
        <li>{{text}}</li>
        {{each}}
    </ul>
</body>

</html>

Firebase.json 文件:

{
  "hosting": {
    "public": "public",
    "rewrites": [{
      "source": "**",
      "function": "app"
    }],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

Firebase 函数日志错误消息:

app
Error: Parse error on line 21: ...ul></body></html> --------------------^ Expecting 'OPEN_INVERSE_CHAIN', 'INVERSE', 'OPEN_ENDBLOCK', got 'EOF' at Parser.parseError 
(/srv/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:267:19) at Parser.parse 
(/srv/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:336:30) at parseWithoutProcessing 
(/srv/node_modules/handlebars/dist/cjs/handlebars/compiler/base.js:46:33) at HandlebarsEnvironment.parse 
(/srv/node_modules/handlebars/dist/cjs/handlebars/compiler/base.js:52:13) at compileInput 
(/srv/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:508:19) at ret 
(/srv/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:517:18) at /srv/node_modules/consolidate/lib/consolidate.js:935:16 at /srv/node_modules/consolidate/lib/consolidate.js:161:5 at Promise._execute 
(/srv/node_modules/bluebird/js/release/debuggability.js:384:9) at Promise._resolveFromExecutor 
(/srv/node_modules/bluebird/js/release/promise.js:518:18) at new Promise 
(/srv/node_modules/bluebird/js/release/promise.js:103:10) at promisify 
(/srv/node_modules/consolidate/lib/consolidate.js:154:10) at Function.exports.handlebars.render 
(/srv/node_modules/consolidate/lib/consolidate.js:925:10) at /srv/node_modules/consolidate/lib/consolidate.js:180:25 at readPartials 
(/srv/node_modules/consolidate/lib/consolidate.js:116:33) at /srv/node_modules/consolidate/lib/consolidate.js:174:7

在index.hbs

中的每个结束前添加一个/
{{/each}}