Skip to content

Commit

Permalink
[REFACTOR] separate the configs into dev & prod
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonGyu1 committed Jan 15, 2022
1 parent f161a4a commit fba68cd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
21 changes: 15 additions & 6 deletions functions/config/dbConfig.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const dotenv = require('dotenv');
dotenv.config();

module.exports = {
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_DB,
password: process.env.DB_PASSWORD,
};
if (process.env.NODE_ENV === 'production') {
module.exports = {
user: process.env.PROD_DB_USER,
host: process.env.PROD_DB_HOST,
database: process.env.PROD_DB_DB,
password: process.env.PROD_DB_PASSWORD,
};
} else {
module.exports = {
user: process.env.DEV_DB_USER,
host: process.env.DEV_DB_HOST,
database: process.env.DEV_DB_DB,
password: process.env.DEV_DB_PASSWORD,
};
}
34 changes: 25 additions & 9 deletions functions/config/firebaseClient.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
const { initializeApp } = require('firebase/app');
const { getAuth } = require('firebase/auth');

const firebaseConfig = {
apiKey: 'AIzaSyDPhxX8Eq0C-GJNPCbFMZolZQE0l2EIlxY',
authDomain: 'teamble-server.firebaseapp.com',
projectId: 'teamble-server',
storageBucket: 'teamble-server.appspot.com',
messagingSenderId: '2748747111',
appId: '1:2748747111:web:76f745d73c74b24c0673c2',
measurementId: 'G-3BVQT7YS2M',
};
let firebaseConfig;

if (process.env.NODE_ENV === 'production') {
// 배포 모드
firebaseConfig = {
apiKey: 'AIzaSyDPhxX8Eq0C-GJNPCbFMZolZQE0l2EIlxY',
authDomain: 'teamble-server.firebaseapp.com',
projectId: 'teamble-server',
storageBucket: 'teamble-server.appspot.com',
messagingSenderId: '2748747111',
appId: '1:2748747111:web:76f745d73c74b24c0673c2',
measurementId: 'G-3BVQT7YS2M',
};
} else {
// 개발 모드
firebaseConfig = {
apiKey: 'AIzaSyDL3LyfLHPnTESsyx-IBCXlqa4q0vaAA0o',
authDomain: 'teamble-server-local.firebaseapp.com',
projectId: 'teamble-server-local',
storageBucket: 'teamble-server-local.appspot.com',
messagingSenderId: '381979822758',
appId: '1:381979822758:web:9c9251bb8b51762c134267',
measurementId: 'G-1KPRKVJK5K',
};
}

const firebaseApp = initializeApp(firebaseConfig);
const firebaseAuth = getAuth(firebaseApp);
Expand Down
11 changes: 10 additions & 1 deletion functions/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const admin = require('firebase-admin');
const serviceAccount = require('./teamble-server-firebase-adminsdk-qy3jy-abef10cd0d.json');
let serviceAccount;

if (process.env.NODE_ENV === 'production') {
// 배포 모드
serviceAccount = require('./teamble-server-firebase-adminsdk-qy3jy-abef10cd0d.json');
} else {
// 개발 모드
serviceAccount = require('./teamble-server-local-firebase-adminsdk-uk7hm-5f9d2ca9b9.json');
}

const dotenv = require('dotenv');

dotenv.config();
Expand Down
4 changes: 2 additions & 2 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "cross-env NODE_ENV=development firebase emulators:start --only functions",
"serve": "cross-env NODE_ENV=development firebase emulators:start --only functions --project dev",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "cross-env NODE_ENV=production firebase deploy --only functions",
"deploy": "cross-env NODE_ENV=production firebase deploy --only functions --project prod",
"logs": "firebase functions:log"
},
"engines": {
Expand Down

0 comments on commit fba68cd

Please sign in to comment.