import { NextRequest, NextResponse } from 'next/server' const PYTHON_API_URL = process.env.PYTHON_API_URL || 'http://localhost:5000' // API route configuration - dynamic for POST requests export const dynamic = 'force-dynamic' export const runtime = 'nodejs' export async function POST(request: NextRequest) { try { const body = await request.json() const { current_build, budget, compatibility_info } = body // Create AbortController for timeout const controller = new AbortController() const timeoutId = setTimeout(() => controller.abort(), 30000) // 30 second timeout try { // Call Python backend const response = await fetch(`${PYTHON_API_URL}/api/graph`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ current_build, budget: budget || null, compatibility_info: compatibility_info || null, }), signal: controller.signal, }) clearTimeout(timeoutId) // Check content-type to ensure we're getting JSON, not HTML const contentType = response.headers.get('content-type') || '' const isJSON = contentType.includes('application/json') if (!response.ok) { let errorMessage = 'Failed to get upgrade recommendations from algorithm' try { const errorText = await response.text() console.error('Python API error:', errorText) // If response is HTML (error page), provide helpful message if (!isJSON || errorText.trim().startsWith('