Alright, Im really just missing a fundamental understanding here of what is going on. What I want to do is:
-
Use firebase for hosting and database - right now this works because I originally set the app up as a firebase app
-
Use Heroku for SERVER only - my reason is Google Cloud functions are limited and won't let me make external aPI calls on a free plan, etc
Im a little new to this setup but so far I have followed http://ift.tt/2eSO53t and Heroku's setup instructions. My project - where public is my public html/files:
Ive run npm install and want to have heroku run server.js as my Server code. Running locally and officially, Ive been using
firebase serve
firebase deploy
These both work without error, but no server code gets run. Trying heroku open or heroku local
, it crashes with error:
firebase experimental:functions:shell 2017-12-02T18:19:41.474319+00:00 app[web.1]: npm ERR! file sh 2017-12-02T18:19:41.471559+00:00 app[web.1]: sh: 1: firebase: not found
Here is server.js, just trying a simple test:
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: "http://ift.tt/2ABgTLH"
});
'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);
})
and package.json (top part is left over from trying cloud functions):
{
"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
}
I downloaded my private key from Firebase when doing the .initializeApp
bit as the tutorial states, so that should all be hooked up.
What am I doing wrong here?
Aucun commentaire:
Enregistrer un commentaire