Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const database = (() => {
log('Connecting to Firebase...');
try {
const firestore = new Firestore({
projectId: process.env.FIREBASE_PROJECT,
keyFilename: path.join(
__dirname,
`../../../${process.env.FIREBASE_KEYFILE}`
),
});
const methods = Object.create(null);
// Inspired my Mongoist
return new Proxy(firestore, {
get: (obj, prop) => {
const fbProp = obj[prop];
// Cache, lazily
if (typeof fbProp === 'function') {
import Firestore from '@google-cloud/firestore';
import Config from '../config';
const firestoreConfig = Config.cloud['firestore'];
const db = new Firestore({
projectId: firestoreConfig['projectId'],
keyFilename: firestoreConfig['keyFilename'],
});
export default db;