Skip to content

Commit

Permalink
Set Phlask DB dynamically (#508)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cjfit authored Aug 24, 2024
1 parent c02a14e commit 39275fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 48 deletions.
1 change: 1 addition & 0 deletions .github/workflows/betasite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 5 additions & 43 deletions src/components/AddResourceModal/utils.js
Original file line number Diff line number Diff line change
@@ -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'
);
15 changes: 10 additions & 5 deletions src/firebase/firebaseConfig.js
Original file line number Diff line number Diff line change
@@ -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'
};
};

0 comments on commit 39275fb

Please sign in to comment.