diff --git a/RT/app.js b/RT/app.js new file mode 100644 index 0000000..fa608df --- /dev/null +++ b/RT/app.js @@ -0,0 +1,25 @@ +import express, { query } from 'express'; +import { createDatabaseConnection } from '../db/database.js'; // db 연결 파일 +import { HandlePush } from './push.js'; +import { rtDBConfig } from '../private/config.js'; + +// const cmcd = "/JJ"; +// const db = "/JJ/db"; + +const app = express(); +app.use(express.json()); + + +// DB 연결 테스트 +app.get(`${db}/test`, async (req, res) => { + try { + const connection = await createDatabaseConnection(dbConfig); + const [rows] = await connection.query('SELECT * FROM version'); + await connection.end(); + res.json({ result: rows[0].solution }); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +export default app; \ No newline at end of file diff --git a/db/database.js b/db/database.js new file mode 100644 index 0000000..abae567 --- /dev/null +++ b/db/database.js @@ -0,0 +1,16 @@ + +import mysql from 'mysql2/promise'; + +// 데이터베이스 연결 설정 함수 +export const createDatabaseConnection = (config) => { + return mysql.createConnection({ + host: config.host, + user: config.user, + password: config.password, + database: config.database, + port: config.port, + waitForConnections: true, + connectionLimit: 10, + queueLimit: 0 + }); +}; \ No newline at end of file diff --git a/index.js b/index.js index cad580b..e7143b0 100755 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ import { fileURLToPath } from 'url'; import cors from 'cors'; import fetch from 'node-fetch'; import session from 'express-session'; // express-session 추가 +import rtRoutes from './RT/app.js'; // ./RT/app.js에서 라우트를 가져옴 const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -29,6 +30,11 @@ app.use(express.static(path.join(__dirname, '..', 'front', 'login'))); let sessionId = ''; // 세션 ID를 저장할 변수 +// ===== RT 설정 ===== // +app.use('/RT', rtRoutes); + + + // login app.get('/login', (req, res) => { res.sendFile(path.join(__dirname, '..', 'front', 'login', 'login.html'));