我正在尝试使用环境变量配置Firebase项目,但遇到了问题。我确定你们中的某些人/女孩将能够为我提供帮助,因此我将直接介绍代码
import Rebase from 're-base';
import firebase from 'firebase';
const config = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGEBUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID
};
const app = firebase.initializeApp(config);
const base = Rebase.createClass(app.database());
const facebookProvider = new firebase.auth.FacebookAuthProvider();
export { app,base,facebookProvider };
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
const PORT = process.env.PORT || 3001;
const app = express();
const router = require('./routes');
const mongoose = require('mongoose');
require('dotenv').config();
// Define middleware here
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.use(router);
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/cryptoTracker")
app.listen(PORT, () => {
console.log(` ==> Server now on port ${PORT}!`);
});
@ firebase /数据库:FIREBASE致命错误:无法确定Firebase数据库URL。调用firebase.initializeApp()时,请确保包括databaseURL选项。
我很困惑,因为我确实有一个databaseURL参数,并且环境变量IS在我的.env文件中定义。出于明显的原因,我没有在此处发布.env文件,但向您保证,我正在调用的所有变量都位于该文件内。