diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-09 10:32:34 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-09 10:32:34 +0000 |
| commit | c62ec046327fd388ebce04571b55910747e69a3b (patch) | |
| tree | 41ccdc4a8dea99808622f6d5d52014ac59a2d7ab /app/api | |
| parent | ebcec3f296d1d27943caf8a3aed26efef117cdc5 (diff) | |
(정희성, 최겸, 대표님) formatDate 변경 등
Diffstat (limited to 'app/api')
| -rw-r--r-- | app/api/basic-contract/get-template/route.ts | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/app/api/basic-contract/get-template/route.ts b/app/api/basic-contract/get-template/route.ts index 111532f0..ad30ae89 100644 --- a/app/api/basic-contract/get-template/route.ts +++ b/app/api/basic-contract/get-template/route.ts @@ -26,8 +26,27 @@ export async function POST(request: NextRequest) { return NextResponse.json({ error: '템플릿 파일 경로가 없습니다.' }, { status: 404 }); } - // 파일 시스템에서 파일 읽기 - const fullPath = path.join(process.cwd(), "public", template.filePath); + // 환경에 따른 파일 경로 설정 + let fullPath: string; + + if (process.env.NODE_ENV === 'production') { + // production: NAS 경로 사용 + const nasPath = process.env.NAS_PATH || "/evcp_nas"; + // template.filePath가 /api/files/로 시작하는 경우 제거하고 basicContract로 시작하도록 정리 + const cleanPath = template.filePath.startsWith('/api/files/') + ? template.filePath.replace('/api/files/', '') + : template.filePath.startsWith('/') + ? template.filePath.slice(1) + : template.filePath; + fullPath = path.join(nasPath, cleanPath); + } else { + // development: public 폴더 사용 + // template.filePath에서 앞의 슬래시를 제거 + const cleanPath = template.filePath.startsWith('/') ? template.filePath.slice(1) : template.filePath; + fullPath = path.join(process.cwd(), "public", cleanPath); + } + + console.log(`📁 템플릿 파일 경로: ${fullPath} (환경: ${process.env.NODE_ENV})`); try { const fileBuffer = await fs.readFile(fullPath); @@ -42,7 +61,13 @@ export async function POST(request: NextRequest) { }); } catch (fileError) { console.error('파일 읽기 오류:', fileError); - return NextResponse.json({ error: '템플릿 파일을 읽을 수 없습니다.' }, { status: 500 }); + console.error(`파일 경로: ${fullPath}`); + console.error(`template.filePath: ${template.filePath}`); + return NextResponse.json({ + error: '템플릿 파일을 읽을 수 없습니다.', + details: `파일 경로: ${fullPath}`, + originalPath: template.filePath + }, { status: 500 }); } } catch (error) { |
