1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.firebaseConfig = exports.resetCache = void 0;
|
4 | const fs_1 = require("fs");
|
5 | const path = require("path");
|
6 | const logger = require("../logger");
|
7 | let cache = null;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function resetCache(newCache = null) {
|
13 | cache = newCache;
|
14 | }
|
15 | exports.resetCache = resetCache;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | function firebaseConfig() {
|
21 | if (cache) {
|
22 | return cache;
|
23 | }
|
24 | let env = process.env.FIREBASE_CONFIG;
|
25 | if (env) {
|
26 |
|
27 |
|
28 |
|
29 | if (!env.startsWith("{")) {
|
30 | env = (0, fs_1.readFileSync)(path.join(process.env.PWD, env)).toString("utf8");
|
31 | }
|
32 | cache = JSON.parse(env);
|
33 | return cache;
|
34 | }
|
35 | if (process.env.GCLOUD_PROJECT) {
|
36 | logger.warn("Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail");
|
37 | cache = {
|
38 | databaseURL: process.env.DATABASE_URL || `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
|
39 | storageBucket: process.env.STORAGE_BUCKET_URL || `${process.env.GCLOUD_PROJECT}.appspot.com`,
|
40 | projectId: process.env.GCLOUD_PROJECT,
|
41 | };
|
42 | return cache;
|
43 | }
|
44 | else {
|
45 | logger.warn("Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail");
|
46 | }
|
47 | return null;
|
48 | }
|
49 | exports.firebaseConfig = firebaseConfig;
|