Files
aerbim-ht-monitor/frontend/app/api/get-detectors-data/route.ts

28 lines
889 B
TypeScript

import { NextResponse } from 'next/server'
import { readFile } from 'fs/promises'
import { join } from 'path'
export async function GET() {
try {
// Имитация полученных данных в формате json (данные в data/detectors.json)
const filePath = join(process.cwd(), 'frontend', 'data', 'detectors.json')
const fileContent = await readFile(filePath, 'utf8')
const allData = JSON.parse(fileContent)
return NextResponse.json({
success: true,
data: allData,
objectsCount: Object.keys(allData.objects || {}).length,
detectorsCount: Object.keys(allData.detectors || {}).length
})
} catch (error) {
console.error('Error fetching detectors data:', error)
return NextResponse.json(
{
success: false,
error: 'Failed to fetch detectors data'
},
{ status: 500 }
)
}
}