30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { parseEmail } from '@/lib/server/email-parser';
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await request.json();
|
|
console.log('Received request body:', body);
|
|
|
|
const { emailContent } = body;
|
|
console.log('Email content type:', typeof emailContent);
|
|
console.log('Email content length:', emailContent?.length);
|
|
|
|
if (!emailContent || typeof emailContent !== 'string') {
|
|
console.log('Invalid email content:', { emailContent, type: typeof emailContent });
|
|
return NextResponse.json(
|
|
{ error: 'Invalid email content. Expected a string.', received: { type: typeof emailContent, length: emailContent?.length } },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const parsed = await parseEmail(emailContent);
|
|
return NextResponse.json(parsed);
|
|
} catch (error) {
|
|
console.error('Error parsing email:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to parse email', details: error instanceof Error ? error.message : 'Unknown error' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|