import { NextRequest, NextResponse } from "next/server"; import { readFile } from "fs/promises"; import path from "path"; export async function POST(request: NextRequest) { try { const { templatePath } = await request.json(); if (!templatePath) { return NextResponse.json( { error: "템플릿 경로가 필요합니다." }, { status: 400 } ); } const fullPath = path.join(process.cwd(), process.env.NAS_PATH, templatePath); const fileBuffer = await readFile(fullPath); return new NextResponse(fileBuffer, { headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'Content-Disposition': `attachment; filename="template.docx"` } }); } catch (error) { console.error("템플릿 파일 읽기 실패:", error); return NextResponse.json( { error: "템플릿 파일을 읽을 수 없습니다." }, { status: 500 } ); } }