TechScout/dashboard/app/api/discoveries/[id]/route.ts

27 lines
806 B
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import * as fs from 'fs';
import * as path from 'path';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
const analysesDir = path.resolve(process.cwd(), '..', 'analyses');
const filePath = path.join(analysesDir, `discovery_${id}.json`);
try {
if (!fs.existsSync(filePath)) {
return NextResponse.json({ error: 'Discovery not found' }, { status: 404 });
}
const content = fs.readFileSync(filePath, 'utf-8');
const data = JSON.parse(content);
return NextResponse.json(data);
} catch (error) {
console.error('Failed to load discovery:', error);
return NextResponse.json({ error: String(error) }, { status: 500 });
}
}