This commit is contained in:
parent
ec547ae098
commit
6a7fa38b96
25
RT/app.js
Normal file
25
RT/app.js
Normal file
|
@ -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;
|
16
db/database.js
Normal file
16
db/database.js
Normal file
|
@ -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
|
||||
});
|
||||
};
|
6
index.js
6
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'));
|
||||
|
|
Loading…
Reference in New Issue
Block a user