Next.js 16, React 19, Monaco editor, Anthropic SDK, multi-provider AI, Wandbox Python execution, iframe HTML preview, SQLite auth + session persistence. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { executePython } from '@/lib/pistonClient';
|
|
import type { ExecuteRequestBody } from '@/types';
|
|
|
|
const MAX_CODE_LENGTH = 10_000;
|
|
|
|
export async function POST(req: NextRequest) {
|
|
let body: ExecuteRequestBody;
|
|
|
|
try {
|
|
body = await req.json();
|
|
} catch {
|
|
return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 });
|
|
}
|
|
|
|
const { language, code, stdin } = body;
|
|
|
|
if (!language || !code) {
|
|
return NextResponse.json({ error: 'Missing language or code' }, { status: 400 });
|
|
}
|
|
|
|
if (code.length > MAX_CODE_LENGTH) {
|
|
return NextResponse.json({ error: 'Code exceeds maximum length of 10,000 characters' }, { status: 400 });
|
|
}
|
|
|
|
// HTML is rendered client-side via iframe — no backend execution needed
|
|
if (language === 'html') {
|
|
return NextResponse.json({
|
|
stdout: '',
|
|
stderr: '',
|
|
exitCode: 0,
|
|
timedOut: false,
|
|
});
|
|
}
|
|
|
|
const result = await executePython(code, stdin ?? '');
|
|
return NextResponse.json(result);
|
|
}
|