无法使用heroku服务器与firebase数据库一起工作? Heroku崩溃了?

时间:2017-12-02 18:26:53

标签: html node.js firebase heroku web

好吧,我真的只是错过了对正在发生的事情的基本了解。我想做的是:

  1. 使用firebase进行托管和数据库 - 现在这可行,因为我最初将应用程序设置为firebase应用程序

  2. 仅将Heroku用于SERVER - 我的理由是Google Cloud功能有限,不允许我在免费计划上进行外部aPI调用等

  3. 我对这个设置有点新,但到目前为止,我已经遵循了https://firebase.google.com/docs/admin/setup和Heroku的设置说明。我的项目 - public是我的公共html /文件:

    enter image description here

    我运行npm install并希望heroku运行server.js作为我的服务器代码。在本地和官方运行,我一直在使用

    firebase serve 
    
    firebase deploy
    

    这些都可以正常运行,但不会运行任何服务器代码。尝试heroku open or heroku local时,它会因错误而崩溃:

      

    firebase实验:功能:shell 2017-12-02T18:19:41.474319 + 00:00   app [web.1]:npm ERR!文件sh 2017-12-02T18:19:41.471559 + 00:00   app [web.1]:sh:1:firebase:not found

    这是server.js,只是尝试一个简单的测试:

    const express = require('express');
    const app = express();
    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    
    // admin.initializeApp(functions.config().firebase);
    
    app.use('/', express.static(__dirname + '/public'));
    
    var serviceAccount = require("diverge-41a46-firebase-adminsdk-4yn47-29b6aaab49.json");
    
    admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: "https://diverge-41a46.firebaseio.com/"
    });
    
    'use strict';
    
    console.log('HELLO WORLD');
    
    const getIP = require('external-ip')();
    var iplocation = require('iplocation');
    
    // exports.helloWorld = functions.https.onRequest((request, response) => {
    //  response.send("Hello from Firebase!");
    // });
    
    // exports.enterLocation = functions.database.ref('/Users/{name}') //brackets is client param
    //     .onWrite(event => {
    //       //console.log('SKYLAR HERE:', event.params.name);
    //       returnLocation();
    //       //-----------------------------------------
    //
    //       return event.data.adminRef.set({ location: 'test loc'});
    //   });
    
    app.get('/', function (req, res) {
      res.send('Hello World');
    })
    
    app.listen(5000, function () { //process.env.PORT || 5000
    console.log('Listening on port ', 5000);
    })
    

    和package.json(顶部是尝试云函数遗留下来的):

    {
      "name": "functions",
      "description": "Cloud Functions for Firebase",
      "scripts": {
        "serve": "firebase serve --only functions",
        "shell": "firebase experimental:functions:shell",
        "start": "npm run shell",
        "deploy": "firebase deploy --only functions",
        "logs": "firebase functions:log"
      },
      "dependencies": {
        "express": "^4.16.2",
        "external-ip": "^1.3.1",
        "firebase-admin": "^5.5.0",
        "firebase-functions": "^0.7.3",
        "iplocation": "^5.0.0",
        "request": "^2.83.0"
      },
      "private": true
    }
    

    我在执行.initializeApp位时从Firebase下载了我的私钥,如同教程所述,所以应该全部连接起来。

    我在这里做错了什么?

0 个答案:

没有答案