UNPKG

tanam

Version:

Pluggable CMS for Firebase

37 lines 2.04 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const admin = require("firebase-admin"); const functions = require("firebase-functions"); const site_info_service_1 = require("../services/site-info.service"); exports.registerHost = functions.database.ref('tanam/{siteId}/domains/{hash}').onCreate((snap) => __awaiter(this, void 0, void 0, function* () { const promises = []; const host = snap.val(); console.log(`[registerHost] Discovered request to new host: ${host}`); const siteInfoDoc = admin.firestore().collection('tanam').doc(process.env.GCLOUD_PROJECT); promises.push(admin.firestore().runTransaction((trx) => __awaiter(this, void 0, void 0, function* () { const trxDoc = yield trx.get(siteInfoDoc); const trxSettings = trxDoc.data(); trxSettings.domains = trxSettings.domains || []; if (trxSettings.domains.indexOf(host) === -1) { console.log(`Discovered adding '${host}' to domain configuration`); trxSettings.domains.push(host); trx.update(siteInfoDoc, trxSettings); } }))); return Promise.all(promises); })); exports.testingSetDefaultData = functions.database.ref('setDefaultData').onCreate((snap) => __awaiter(this, void 0, void 0, function* () { return Promise.all([ site_info_service_1.initializeSite(true), snap.ref.remove(), ]); })); //# sourceMappingURL=site.js.map