From 39275fb4ead10c397421f4cd6c0c676a610ba281 Mon Sep 17 00:00:00 2001 From: Cedric Fitzgerald Date: Sat, 24 Aug 2024 08:17:25 -0400 Subject: [PATCH] Set Phlask DB dynamically (#508) * Remove unused firebase config * Default Firebase DB to test * Add Prod Firebase DB as env var to action * Change URL from prod->beta per aaron --- .github/workflows/betasite.yml | 1 + src/components/AddResourceModal/utils.js | 48 +++--------------------- src/firebase/firebaseConfig.js | 15 +++++--- 3 files changed, 16 insertions(+), 48 deletions(-) diff --git a/.github/workflows/betasite.yml b/.github/workflows/betasite.yml index 079bed9a..0a325c18 100644 --- a/.github/workflows/betasite.yml +++ b/.github/workflows/betasite.yml @@ -6,6 +6,7 @@ on: - develop env: AWS_DEFAULT_REGION: us-east-2 + REACT_APP_DB_URL: https://phlask-beta.firebaseio.com permissions: id-token: write # This is required for requesting the JWT contents: read # This is required for actions/checkout diff --git a/src/components/AddResourceModal/utils.js b/src/components/AddResourceModal/utils.js index faa7dcf8..ef1c6589 100644 --- a/src/components/AddResourceModal/utils.js +++ b/src/components/AddResourceModal/utils.js @@ -1,47 +1,9 @@ -import { initializeApp } from 'firebase/app'; - -export const connectToFirebase = (hostname, resourceType) => { - // TODO -- OLD PROD CONFIG -- DOUBLECHECK IF THIS IS NEEDED - // const prodConfig = { - // apiKey: "AIzaSyA2E1tiV34Ou6CJU_wzlJtXxwATJXxi6K8", - // authDomain: "phlask-web-map-new-taps.firebaseapp.com", - // databaseURL: `https://phlask-web-map-new-taps.firebaseio.com`, - // projectId: "phlask-web-map-new-taps", - // storageBucket: "phlask-web-map-new-taps.appspot.com", - // messagingSenderId: "673087230724", - // appId: "1:673087230724:web:2545788342843cccdcf651" - // }; - - let environment; - - if (hostname === 'phlask.me') { - environment = 'prod'; - } else if (hostname === 'beta.phlask.me') { - environment = 'beta'; - } else { - environment = 'test'; - } - - const firebaseConfig = { - apiKey: 'AIzaSyABw5Fg78SgvedyHr8tl-tPjcn5iFotB6I', - authDomain: 'phlask-web-map.firebaseapp.com', - databaseURL: `https://phlask-web-map-${environment}-${resourceType}-verify.firebaseio.com`, - projectId: 'phlask-web-map-new-taps', - storageBucket: 'phlask-web-map.appspot.com', - messagingSenderId: '428394983826', - appId: '1:428394983826:web:b81abdcfd5af5401e0514b' - }; - - // return firebase.initializeApp(firebaseConfig, "new"); - return initializeApp(firebaseConfig, 'new'); -}; - export const WEBSITE_REGEX = new RegExp( '^([a-zA-Z]+:\\/\\/)?' + // protocol (optional) - '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name - '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR IP (v4) address - '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path - '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string - '(\\#[-a-z\\d_]*)?$', // fragment locator + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name + '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR IP (v4) address + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path + '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string + '(\\#[-a-z\\d_]*)?$', // fragment locator 'i' ); diff --git a/src/firebase/firebaseConfig.js b/src/firebase/firebaseConfig.js index 52ee2130..b0d4648d 100644 --- a/src/firebase/firebaseConfig.js +++ b/src/firebase/firebaseConfig.js @@ -1,17 +1,22 @@ -export const contributorsConfig = { +// Sets the Phlask Database URL to use the test instance unless overriden +// This environment variable will also need to be set in the prod build pipeline to "https://phlask-prod.firebaseio.com" +// https://github.com/phlask/phlask-map/issues/498 +let phlaskDatabaseUrl = process.env.REACT_APP_DB_URL || "https://phlask-test.firebaseio.com" + +export const resourcesConfig = { apiKey: 'AIzaSyABw5Fg78SgvedyHr8tl-tPjcn5iFotB6I', authDomain: 'phlask-web-map.firebaseapp.com', - databaseURL: 'https://phlask-contributors.firebaseio.com/', + databaseURL: phlaskDatabaseUrl, projectId: 'phlask-web-map', storageBucket: 'phlask-web-map.appspot.com', messagingSenderId: '428394983826' }; -export const resourcesConfig = { +export const contributorsConfig = { apiKey: 'AIzaSyABw5Fg78SgvedyHr8tl-tPjcn5iFotB6I', authDomain: 'phlask-web-map.firebaseapp.com', - databaseURL: 'https://phlask-beta.firebaseio.com', + databaseURL: 'https://phlask-contributors.firebaseio.com/', projectId: 'phlask-web-map', storageBucket: 'phlask-web-map.appspot.com', messagingSenderId: '428394983826' -}; +}; \ No newline at end of file