19 lines
No EOL
527 B
TypeScript
19 lines
No EOL
527 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const { filePath } = await request.json();
|
|
const normalizedPath = path.normalize(filePath);
|
|
const content= fs.readFileSync(normalizedPath, 'utf-8');
|
|
|
|
return NextResponse.json({ content });
|
|
} catch (error) {
|
|
console.error('Error reading file:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to read file' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|