2025-06-28 15:16:06 +08:00

25 lines
626 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { withCors } from '@/lib/middleware'
async function handleHostsList(req: NextRequest) {
try {
const hosts = await prisma.host.findMany({
select: {
hostname: true,
lastUpdate: true
},
orderBy: {
lastUpdate: 'desc'
}
})
return NextResponse.json(hosts)
} catch (error) {
console.error('获取主机列表失败:', error)
return NextResponse.json({ error: '获取主机列表失败' }, { status: 500 })
}
}
export const GET = withCors(handleHostsList)