diff --git a/apps/app.js b/apps/app.js index ed8bb19..58dc4ef 100644 --- a/apps/app.js +++ b/apps/app.js @@ -1,88 +1,75 @@ import express, { query } from 'express'; import { createDatabaseConnection } from '../db/database.js'; // db 연결 파일 import { HandlePush } from './push.js'; +import { dbConfig } from '../private/config.js'; -const cmcd = "/JJ"; -const db = "/JJ/db"; +// const cmcd = "/JJ"; +// const db = "/JJ/db"; const app = express(); app.use(express.json()); -const dbConfig = { - host: 'ipStein.myDS.me', - user: 'root', - password: 'JJrootPW', - database: 'dev', - port: 8002 -}; - -/* - // query 클래스 묶음 - let query; - query = await getQueryModule('update', 'Update'); - if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } -*/ -const getQueryModule = async (type, className) => { - if (type === 'create') { - const module = await import('../../db/queries/create_query.js'); - return module[className]; - } - else if (type === 'read') { - const module = await import('../../db/queries/read_query.js'); - return module[className]; - } - else if (type === 'update') { - const module = await import('../../db/queries/update_query.js'); - return module[className]; - } - else if (type === 'delete') { - const module = await import('../../db/queries/update_query.js'); - return module[className]; - } - else if (type === 'function') { - const module = await import('../../db/queries/functions_query.js'); - return module[className]; - } - return '' -}; +// const getQueryModule = async (type, className) => { +// if (type === 'create') { +// const module = await import('../../db/queries/create_query.js'); +// return module[className]; +// } +// else if (type === 'read') { +// const module = await import('../../db/queries/read_query.js'); +// return module[className]; +// } +// else if (type === 'update') { +// const module = await import('../../db/queries/update_query.js'); +// return module[className]; +// } +// else if (type === 'delete') { +// const module = await import('../../db/queries/update_query.js'); +// return module[className]; +// } +// else if (type === 'function') { +// const module = await import('../../db/queries/functions_query.js'); +// return module[className]; +// } +// return '' +// }; -app.get(`${cmcd}/push`, async (req, res) => { - // HandlePush(req, res); - //3138117983JJ20240611 - // const { cid, title, body, cd } = req.query; - const { cid, title, body, badge, parameter } = req.query; +// app.get(`${cmcd}/push`, async (req, res) => { +// // HandlePush(req, res); +// //3138117983JJ20240611 +// // const { cid, title, body, cd } = req.query; +// const { cid, title, body, badge, parameter } = req.query; - if (!cid || !title || !body) { - return res.status(400).json({ error: 'All parameters (cid, title, body) are required' }); - } +// if (!cid || !title || !body) { +// return res.status(400).json({ error: 'All parameters (cid, title, body) are required' }); +// } - let query; - query = await getQueryModule('function', 'Push'); - if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } +// let query; +// query = await getQueryModule('function', 'Push'); +// if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } - try { - const connection = await createDatabaseConnection({ ...dbConfig, database: 'jjungtable_db'}); - const [rows] = await connection.query(query.loadFCM_token, [cid]); - await connection.end(); +// try { +// const connection = await createDatabaseConnection({ ...dbConfig, database: 'jjungtable_db'}); +// const [rows] = await connection.query(query.loadFCM_token, [cid]); +// await connection.end(); - if (rows.length === 0) { - return res.status(404).json({ error: 'No fcm_token found for the provided cid' }); - } +// if (rows.length === 0) { +// return res.status(404).json({ error: 'No fcm_token found for the provided cid' }); +// } - const fcmToken = rows[0].fcm_token; - console.log(fcmToken); - // HandlePush 호출 시 필요한 req.body에 fcmToken, title, body 설정 - req.body = { fcmToken, title, body, badge, parameter }; - HandlePush(req, res); +// const fcmToken = rows[0].fcm_token; +// console.log(fcmToken); +// // HandlePush 호출 시 필요한 req.body에 fcmToken, title, body 설정 +// req.body = { fcmToken, title, body, badge, parameter }; +// HandlePush(req, res); - } catch (err) { - console.error(err); - res.status(500).json({ error: 'Internal server error' }); - } -}); +// } catch (err) { +// console.error(err); +// res.status(500).json({ error: 'Internal server error' }); +// } +// }); // DB 연결 테스트 @@ -98,120 +85,120 @@ app.get(`${db}/test`, async (req, res) => { }); -/////////////////////////////////////////////////////////////// -// GET -/////////////////////////////////////////////////////////////// -app.get(`${db}/version/read`, async (req, res) => { - const { os_type } = req.query; - if (!os_type) { return res.status(400).json({ error: 'ostype parameter is required' }) } +// /////////////////////////////////////////////////////////////// +// // GET +// /////////////////////////////////////////////////////////////// +// app.get(`${db}/version/read`, async (req, res) => { +// const { os_type } = req.query; +// if (!os_type) { return res.status(400).json({ error: 'ostype parameter is required' }) } - let query; - query = await getQueryModule('read', 'Read'); - if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } +// let query; +// query = await getQueryModule('read', 'Read'); +// if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } - try { - const connection = await createDatabaseConnection({ ...dbConfig, database: 'jjungtable_db' }); - const [rows] = await connection.query(query.version, [os_type]); - await connection.end(); +// try { +// const connection = await createDatabaseConnection({ ...dbConfig, database: 'jjungtable_db' }); +// const [rows] = await connection.query(query.version, [os_type]); +// await connection.end(); - if (rows.length === 0) { - return res.status(404).json({ error: 'No data found' }); - } +// if (rows.length === 0) { +// return res.status(404).json({ error: 'No data found' }); +// } - res.json(rows); - } catch (err) { - console.error(err); - res.status(500).json({ error: 'Internal server error' }); - } -}); +// res.json(rows); +// } catch (err) { +// console.error(err); +// res.status(500).json({ error: 'Internal server error' }); +// } +// }); -app.get(`${db}/userInfo/read`, async (req, res) => { - const { id, type } = req.query; - if (!id || !type) { return res.status(400).json({ error: 'ostype parameter is required' }) } +// app.get(`${db}/userInfo/read`, async (req, res) => { +// const { id, type } = req.query; +// if (!id || !type) { return res.status(400).json({ error: 'ostype parameter is required' }) } - let query; - query = await getQueryModule('read', 'Read'); - if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } +// let query; +// query = await getQueryModule('read', 'Read'); +// if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } - try { - const connection = await createDatabaseConnection({ ...dbConfig, database: 'jjungtable_db' }); - const [rows] = await connection.query(query.login_code, [id, type]); - await connection.end(); +// try { +// const connection = await createDatabaseConnection({ ...dbConfig, database: 'jjungtable_db' }); +// const [rows] = await connection.query(query.login_code, [id, type]); +// await connection.end(); - if (rows.length === 0) { - return res.status(404).json({ error: 'No data found' }); - } +// if (rows.length === 0) { +// return res.status(404).json({ error: 'No data found' }); +// } - res.json(rows); - } catch (err) { - console.error(err); - res.status(500).json({ error: 'Internal server error' }); - } -}); +// res.json(rows); +// } catch (err) { +// console.error(err); +// res.status(500).json({ error: 'Internal server error' }); +// } +// }); -/////////////////////////////////////////////////////////////// -// POST -/////////////////////////////////////////////////////////////// +// /////////////////////////////////////////////////////////////// +// // POST +// /////////////////////////////////////////////////////////////// -async function insertLog(table, connection, query, body) { - if (table === 'version') { - const { date, managerId, os_type, final_ver, force_ver, update_ver, update_choice, log } = body; - await connection.query( query, [date, managerId, os_type, final_ver, force_ver, update_ver, update_choice, log] ); - } -} -app.post(`${db}/version/update`, async (req, res) => { - const { date, managerId, os_type, final_ver, force_ver, update_ver, update_choice, log } = req.body; - try { - const connection = await createDatabaseConnection({ ...dbConfig}); - let query; +// async function insertLog(table, connection, query, body) { +// if (table === 'version') { +// const { date, managerId, os_type, final_ver, force_ver, update_ver, update_choice, log } = body; +// await connection.query( query, [date, managerId, os_type, final_ver, force_ver, update_ver, update_choice, log] ); +// } +// } +// app.post(`${db}/version/update`, async (req, res) => { +// const { date, managerId, os_type, final_ver, force_ver, update_ver, update_choice, log } = req.body; +// try { +// const connection = await createDatabaseConnection({ ...dbConfig}); +// let query; - // 버전 정보 업데이트 - query = await getQueryModule('update', 'Update'); - if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } - await connection.query( query.version,[final_ver, force_ver, update_ver, update_choice, os_type]); +// // 버전 정보 업데이트 +// query = await getQueryModule('update', 'Update'); +// if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } +// await connection.query( query.version,[final_ver, force_ver, update_ver, update_choice, os_type]); - // 로그 생성 - query = await getQueryModule('create', 'Log'); - if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } - await insertLog('version', connection, query.version_Log, req.body); +// // 로그 생성 +// query = await getQueryModule('create', 'Log'); +// if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } +// await insertLog('version', connection, query.version_Log, req.body); - await connection.end(); - res.json({ message: 'Update successful' }); +// await connection.end(); +// res.json({ message: 'Update successful' }); - } catch (err) { - res.status(500).json({ error: err.message }); - } -}); +// } catch (err) { +// res.status(500).json({ error: err.message }); +// } +// }); -/////////////////////////////////////////////////////////////// -// LOG 관련 +// /////////////////////////////////////////////////////////////// +// // LOG 관련 -// DB Log 읽어들이기 -app.get(`${db}/log/read`, async (req, res) => { - console.log('[JJ]Log: Version'); - const { param } = req.query; +// // DB Log 읽어들이기 +// app.get(`${db}/log/read`, async (req, res) => { +// console.log('[JJ]Log: Version'); +// const { param } = req.query; - try { - const connection = await createDatabaseConnection({ ...dbConfig }); - let query, rows; - // let rows; +// try { +// const connection = await createDatabaseConnection({ ...dbConfig }); +// let query, rows; +// // let rows; - if (param === 'version') { - query = await getQueryModule('read', 'Log'); - if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } - [rows] = await connection.query(query.version_Log); - } +// if (param === 'version') { +// query = await getQueryModule('read', 'Log'); +// if (!query) { return res.status(400).json({ error: 'Invalid parameter' }); } +// [rows] = await connection.query(query.version_Log); +// } - await connection.end(); - res.json(rows); - } catch (err) { - console.error(err); - res.status(500).json({ error: 'Internal server error' }); - } -}); +// await connection.end(); +// res.json(rows); +// } catch (err) { +// console.error(err); +// res.status(500).json({ error: 'Internal server error' }); +// } +// }); diff --git a/firebaseConfig.js b/firebaseConfig.js index 3e5d7b6..2b68ac8 100644 --- a/firebaseConfig.js +++ b/firebaseConfig.js @@ -1,52 +1,16 @@ import { initializeApp as initializeClientApp, getApps, getApp } from 'firebase/app'; import admin from 'firebase-admin'; import jjungtable_AccKey from './private/jjungtable-AccountKey.json' assert { type: 'json' }; - -// 첫 번째 파이어베이스 초기화 (관리자) -// if (!admin.apps.find(app => app.name === 'sManager')) { -// admin.initializeApp({ -// credential: admin.credential.cert(sManager_AccKey), -// databaseURL: "https://checkanything-18bf9.firebaseio.com" -// }, 'sManager'); -// } +import { fbURL, jj_firebaseConfig } from './private/config.js'; // 파이어베이스 초기화 if (!admin.apps.find(app => app.name === 'jjungtable')) { admin.initializeApp({ credential: admin.credential.cert(jjungtable_AccKey), - databaseURL: "https://jjungtable-e5087-default-rtdb.firebaseio.com" + databaseURL: fbURL, }, 'jjungtable'); } -// export const sm_firebaseConfig = { -// apiKey: "AIzaSyCxLVOqbrnlDwfx6WMbmTGtCGrUNoL-CqI", -// authDomain: "checkanything-18bf9.firebaseapp.com", -// projectId: "checkanything-18bf9", -// storageBucket: "checkanything-18bf9.appspot.com", -// messagingSenderId: "928156583361", -// appId: "1:928156583361:web:d157abe34e637fb2395b40", -// measurementId: "G-NBSP3XCXX7" -// }; - -export const jj_firebaseConfig = { - apiKey: "AIzaSyCHJI2u1lbmHYgKRvPSO9-mPOGENBBPnsg", - authDomain: "jjungtable-e5087.firebaseapp.com", - databaseURL: "https://jjungtable-e5087-default-rtdb.firebaseio.com", - projectId: "jjungtable-e5087", - storageBucket: "jjungtable-e5087.appspot.com", - messagingSenderId: "480609810019", - appId: "1:480609810019:web:b66f72216fa17e1b462a56", - measurementId: "G-BQP2SDL40C" -}; - -// 클라이언트 앱 초기화 (이미 초기화된 경우 확인) -// let sm_ClientApp; -// if (!getApps().some(app => app.name === 'sManagerClientApp')) { -// sm_ClientApp = initializeClientApp(sm_firebaseConfig, 'sManagerClientApp'); -// } else { -// sm_ClientApp = getApp('sManagerClientApp'); -// } - let jj_ClientApp; if (!getApps().some(app => app.name === 'jjungtableClientApp')) { jj_ClientApp = initializeClientApp(jj_firebaseConfig, 'jjungtableClientApp'); @@ -54,6 +18,4 @@ if (!getApps().some(app => app.name === 'jjungtableClientApp')) { jj_ClientApp = getApp('jjungtableClientApp'); } -// export { admin, sm_ClientApp, jj_ClientApp }; - export { admin, jj_ClientApp }; diff --git a/index.js b/index.js index ac16455..6d6d4fa 100755 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ import { fileURLToPath } from 'url'; import cookieParser from 'cookie-parser'; import cors from 'cors'; -// import jjungTableApp from './back/apps/jjungTable_index.js'; +import { serverURL, serverPort } from './private/config.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -18,6 +18,9 @@ console.log(process.cwd()); const app = express(); + + + app.use(cors()); app.use(bodyParser.json()); // For parsing application/json app.use(cookieParser()); // For parsing cookies @@ -33,8 +36,8 @@ const swaggerDefinition = { }, servers: [ { - url: `http://localhost:7002`, - description: 'Local server', + url: serverURL, + description: 'JJ server', }, ], }; @@ -61,8 +64,8 @@ app.use((req, res, next) => { //JJUNGTABLE 서버 연결 const jjungTable_server = express(); jjungTable_server.use(jjungTableApp); -jjungTable_server.listen(7002, () => { - console.log(`Server running at http://localhost:7002/`); +jjungTable_server.listen(serverPort, () => { + console.log(`Server running`); }); // const sManagement_server = express();