使用Firebase托管和node.js功能时,http返回内部服务器错误

问题描述

我从Firebase托管中收到内部服务器错误,并与node.js一起运行。我按照本教程进行操作,并确保我的代码与他的代码完全相同:https://www.youtube.com/watch?v=LOeioOKUKI8&t=1s&pbjreload=101我甚至对事实数据库都有引用。

这是我的index.js文件

struct ChangingButton: View { 
var text: String
var onButton: String
var offButton: String 
var changeButton: Bool

 var buttonCondition: String {
    if isOn {
        return isOnImage
    } else {
        return isOffImage
    }
}
var body: some View {

    Button(action: {
        action()
    },label: {
        vstack {
           Image(systemName: buttonCondition)             
            Text(text)
        }
    })
 }
}
struct ChangingButton_Previews: PreviewProvider {
static var previews: some View {
    ChangingButton(text: "My Button",onButton: "on",offButton: "off",changeButton: true,action: {
    }).background(Color.black)
}

这是我的index.hbs文件

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

Firebase.json文件

<!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>

database reference

internal_server_error

my_coding_folder

Firebase功能日志错误消息:

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

解决方法

在index.hbs中的每个结尾之前添加一个/。

{{/each}}