修复middleware规则和删除test相关的文件
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
// src/app/api/test/route.ts
|
||||
import { db } from '@/lib/db'
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
// src/app/api/test/route.ts
|
||||
export async function GET() {
|
||||
try {
|
||||
// 测试数据库连接
|
||||
await db.$queryRaw`SELECT 1`
|
||||
|
||||
// 暂时注释掉用户查询,因为表可能还不存在
|
||||
// const users = await db.user.findMany()
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '数据库连接成功',
|
||||
// userCount: users.length,
|
||||
// users: users
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('数据库测试错误:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: '数据库连接失败'
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
|
||||
export default function DebugPage() {
|
||||
const [results, setResults] = useState<Record<string, unknown>>({})
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const testAllEndpoints = async () => {
|
||||
setLoading(true)
|
||||
const endpoints = [
|
||||
'gateway_config',
|
||||
'city_config_count',
|
||||
'city_node_count',
|
||||
'allocation_status',
|
||||
'duplicate_nodes'
|
||||
]
|
||||
|
||||
const results: Record<string, unknown> = {}
|
||||
|
||||
for (const endpoint of endpoints) {
|
||||
try {
|
||||
const response = await fetch(`/api/stats?type=${endpoint}`)
|
||||
results[endpoint] = {
|
||||
status: response.status,
|
||||
data: await response.json()
|
||||
}
|
||||
} catch (error) {
|
||||
results[endpoint] = {
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setResults(results)
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-2xl font-bold mb-4">API调试页面</h1>
|
||||
<button
|
||||
onClick={testAllEndpoints}
|
||||
disabled={loading}
|
||||
className="bg-blue-500 text-white px-4 py-2 rounded disabled:bg-gray-400"
|
||||
>
|
||||
{loading ? '测试中...' : '测试所有API端点'}
|
||||
</button>
|
||||
|
||||
<div className="mt-6">
|
||||
<h2 className="text-xl font-semibold mb-4">测试结果:</h2>
|
||||
<pre className="bg-gray-100 p-4 rounded overflow-auto">
|
||||
{JSON.stringify(results, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<h2 className="text-xl font-semibold mb-4">数据库连接测试:</h2>
|
||||
<button
|
||||
onClick={async () => {
|
||||
try {
|
||||
const response = await fetch('/api/test')
|
||||
const result = await response.json()
|
||||
console.log('数据库测试:', result)
|
||||
alert(JSON.stringify(result, null, 2))
|
||||
} catch (error) {
|
||||
alert('测试失败: ' + (error instanceof Error ? error.message : 'Unknown error'))
|
||||
}
|
||||
}}
|
||||
className="bg-green-500 text-white px-4 py-2 rounded"
|
||||
>
|
||||
测试数据库连接
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
export default async function Home() {
|
||||
const prisma = new PrismaClient()
|
||||
const data = await prisma.change.findMany({ take: 10 })
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>数据库连接成功!</h1>
|
||||
<pre>{JSON.stringify(data, null, 2)}</pre>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// 测试查询
|
||||
const changes = await prisma.change.findMany({
|
||||
take: 5
|
||||
})
|
||||
console.log('✅ 数据库连接成功!')
|
||||
console.log('获取到的数据:', changes)
|
||||
} catch (error) {
|
||||
console.error('❌ 连接失败:', error)
|
||||
} finally {
|
||||
await prisma.$disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user