import { NextResponse } from 'next/server' import mysql from 'mysql2/promise' // 创建全局的 MySQL 连接池 const pool = mysql.createPool({ connectionLimit: 10, host: '192.168.3.89', // 服务器地址 user: 'root', password: '123456', // 密码 database: 'chat', }) export async function GET(request:any) { try { // 从连接池中获取连接 const connection = await pool.getConnection() // 执行 MySQL 查询 const [rows, fields] = await connection.query('SELECT he.id,he.dialog_name,de.id did,de.dialog_id,de.type,de.content FROM dialog he left join dialog_detail de on he.id = de.dialog_id') // 释放连接回连接池 connection.release() return NextResponse.json({ data: rows }, { status: 200 }) } catch (error) { console.error('Error:', error) return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }) } }