好吧,我真的只是错过了对正在发生的事情的基本了解。我想做的是:
使用firebase进行托管和数据库 - 现在这可行,因为我最初将应用程序设置为firebase应用程序
仅将Heroku用于SERVER - 我的理由是Google Cloud功能有限,不允许我在免费计划上进行外部aPI调用等
我对这个设置有点新,但到目前为止,我已经遵循了https://firebase.google.com/docs/admin/setup和Heroku的设置说明。我的项目 - public是我的公共html /文件:
我运行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下载了我的私钥,如同教程所述,所以应该全部连接起来。
我在这里做错了什么?