build: 更新项目结构和配置
- 移除 .gitignore 中的多个文件和目录 - 删除 README.md 文件 - 移除 app.vue 文件 - 删除 nuxt.config.ts 文件
This commit is contained in:
12
server/src/index.ts
Normal file
12
server/src/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import express from 'express';
|
||||
import roleRoutes from './routes/role.routes';
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
// 注册路由
|
||||
app.use('/api', roleRoutes);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is running on http://localhost:${port}`);
|
||||
});
|
||||
30
server/src/routes/role.routes.ts
Normal file
30
server/src/routes/role.routes.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import express from 'express';
|
||||
import { getConnection, query } from '../utils/db.util';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// 获取角色列表
|
||||
router.get('/roles', async (req, res) => {
|
||||
try {
|
||||
const connection = await getConnection();
|
||||
const results = await query('SELECT * FROM role', [], connection);
|
||||
res.json(results);
|
||||
} catch (error) {
|
||||
console.error('获取角色数据失败:', error);
|
||||
res.status(500).json({ error: '获取角色数据失败' });
|
||||
}
|
||||
});
|
||||
|
||||
// 获取充值列表
|
||||
router.get('/recharges', async (req, res) => {
|
||||
try {
|
||||
const connection = await getConnection();
|
||||
const results = await query('SELECT * FROM recharge', [], connection);
|
||||
res.json(results);
|
||||
} catch (error) {
|
||||
console.error('获取充值列表失败:', error);
|
||||
res.status(500).json({ error: '获取充值列表失败' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,8 +1,8 @@
|
||||
import mysql from 'mysql';
|
||||
import { dbConfig } from '../config/db.config';
|
||||
import { cdkDbConfig } from '../config/db.config';
|
||||
|
||||
// 创建连接池
|
||||
const pool = mysql.createPool(dbConfig);
|
||||
const pool = mysql.createPool(cdkDbConfig);
|
||||
|
||||
// 获取数据库连接
|
||||
export const getConnection = (): Promise<mysql.PoolConnection> => {
|
||||
@@ -18,8 +18,10 @@ export const getConnection = (): Promise<mysql.PoolConnection> => {
|
||||
};
|
||||
|
||||
// 执行查询
|
||||
export const query = async (sql: string, values?: any[]): Promise<any> => {
|
||||
const connection = await getConnection();
|
||||
export const query = async (sql: string, values?: any[], connection?: mysql.PoolConnection): Promise<any> => {
|
||||
if (!connection) {
|
||||
connection = await getConnection()
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(sql, values, (err, results) => {
|
||||
connection.release(); // 释放连接
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "../.nuxt/tsconfig.server.json"
|
||||
}
|
||||
Reference in New Issue
Block a user