| |
| |
| |
| |
| |
| |
| |
|
|
| import { NextRequest, NextResponse } from 'next/server'; |
| import { readFile } from 'fs/promises'; |
| import { join } from 'path'; |
|
|
| export async function GET( |
| request: NextRequest, |
| { params }: { params: Promise<{ path: string[] }> } |
| ) { |
| try { |
| const { path } = await params; |
|
|
| |
| const filename = path.join('/'); |
| if (filename.includes('..') || filename.startsWith('/')) { |
| return NextResponse.json( |
| { error: 'Invalid path' }, |
| { status: 400 } |
| ); |
| } |
|
|
| |
| const docsPath = join(process.cwd(), 'docs', filename); |
| const content = await readFile(docsPath, 'utf-8'); |
|
|
| |
| return new NextResponse(content, { |
| headers: { |
| 'Content-Type': 'text/markdown; charset=utf-8', |
| 'Cache-Control': 'public, max-age=3600', |
| }, |
| }); |
| } catch (error) { |
| console.error('[Docs API] Error reading file:', error); |
|
|
| |
| if ((error as NodeJS.ErrnoException).code === 'ENOENT') { |
| return NextResponse.json( |
| { error: 'Document not found' }, |
| { status: 404 } |
| ); |
| } |
|
|
| return NextResponse.json( |
| { error: 'Failed to read document' }, |
| { status: 500 } |
| ); |
| } |
| } |
|
|