|
|
@@ -4,7 +4,7 @@ import mysql from 'mysql2/promise';
|
|
|
// 创建全局的 MySQL 连接池
|
|
|
const pool = mysql.createPool({
|
|
|
connectionLimit: 100,
|
|
|
- host: 'xia0miduo.gicp.net', // 服务器地址
|
|
|
+ host: '127.0.0.1', // 服务器地址
|
|
|
port: 3306,
|
|
|
user: 'root',
|
|
|
password: '123456', // 密码
|
|
|
@@ -21,18 +21,19 @@ interface Request {
|
|
|
}[];
|
|
|
}
|
|
|
|
|
|
-export async function POST(req: Request) {
|
|
|
+export async function POST(req: any) {
|
|
|
try {
|
|
|
// 从连接池中获取连接
|
|
|
const connection = await pool.getConnection()
|
|
|
- const id = req.id;
|
|
|
- const messages = req.messages;
|
|
|
+ const data: Request = await req.json();
|
|
|
+ const id = data.id;
|
|
|
+ const messages = data.messages;
|
|
|
|
|
|
const [rows, fields] = await connection.query('SELECT * FROM dialog where id = ?', [id]);
|
|
|
|
|
|
if (!rows) {
|
|
|
// 执行 MySQL 添加头表
|
|
|
- await connection.execute('INSERT INTO dialog (id, create_time) VALUES (?,?)', [req, new Date])
|
|
|
+ await connection.execute('INSERT INTO dialog (id, create_time) VALUES (?,?)', [data, new Date])
|
|
|
}
|
|
|
|
|
|
messages.forEach(async function (message) {
|
|
|
@@ -50,7 +51,7 @@ export async function POST(req: Request) {
|
|
|
|
|
|
// 释放连接回连接池
|
|
|
connection.release()
|
|
|
- return NextResponse.json({ message: 'ok' }, { status: 200 })
|
|
|
+ return NextResponse.json({ message: 'ok', data: rows }, { status: 200 })
|
|
|
} catch (error) {
|
|
|
console.error('Error:', error)
|
|
|
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
|