56 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
export default defineEventHandler(async (event) => {
 | 
						|
  try {
 | 
						|
    const formData = await readFormData(event);
 | 
						|
    const file = formData.get('fasta');
 | 
						|
    
 | 
						|
    if (!file) {
 | 
						|
      throw createError({
 | 
						|
        statusCode: 400,
 | 
						|
        statusMessage: 'FASTA 파일이 없습니다.'
 | 
						|
      });
 | 
						|
    }
 | 
						|
    
 | 
						|
    // Spring Boot 서버 URL (환경변수로 설정 가능)
 | 
						|
    const springBootUrl = process.env.SPRING_BOOT_URL || 'http://localhost:8080';
 | 
						|
    const uploadUrl = `${springBootUrl}/api/fasta/upload`;
 | 
						|
    
 | 
						|
    // Spring Boot 서버로 파일 전송
 | 
						|
    const springFormData = new FormData();
 | 
						|
    springFormData.append('file', file);
 | 
						|
    
 | 
						|
    console.log(`Spring Boot 서버로 파일 업로드 중: ${uploadUrl}`);
 | 
						|
    
 | 
						|
    const response = await fetch(uploadUrl, {
 | 
						|
      method: 'POST',
 | 
						|
      body: springFormData,
 | 
						|
      headers: {
 | 
						|
        // Content-Type은 FormData가 자동으로 설정
 | 
						|
      }
 | 
						|
    });
 | 
						|
    
 | 
						|
    if (!response.ok) {
 | 
						|
      const errorText = await response.text();
 | 
						|
      throw createError({
 | 
						|
        statusCode: response.status,
 | 
						|
        statusMessage: `Spring Boot 서버 오류: ${errorText}`
 | 
						|
      });
 | 
						|
    }
 | 
						|
    
 | 
						|
    const result = await response.json();
 | 
						|
    console.log('Spring Boot 서버 응답:', result);
 | 
						|
    
 | 
						|
    return {
 | 
						|
      success: true,
 | 
						|
      remoteUrl: result.fileUrl,
 | 
						|
      fileName: result.fileName,
 | 
						|
      fileSize: result.fileSize
 | 
						|
    };
 | 
						|
    
 | 
						|
  } catch (error) {
 | 
						|
    console.error('FASTA 업로드 오류:', error);
 | 
						|
    throw createError({
 | 
						|
      statusCode: 500,
 | 
						|
      statusMessage: `파일 업로드 실패: ${error.message}`
 | 
						|
    });
 | 
						|
  }
 | 
						|
});  |