40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
|
|
import { NextRequest, NextResponse } from 'next/server';
|
||
|
|
import { createSupervisorClient } from '@/lib/supervisor/client';
|
||
|
|
|
||
|
|
export const dynamic = 'force-dynamic';
|
||
|
|
|
||
|
|
// GET main supervisord log
|
||
|
|
export async function GET(request: NextRequest) {
|
||
|
|
try {
|
||
|
|
const searchParams = request.nextUrl.searchParams;
|
||
|
|
const offset = parseInt(searchParams.get('offset') || '-4096', 10);
|
||
|
|
const length = parseInt(searchParams.get('length') || '4096', 10);
|
||
|
|
|
||
|
|
const client = createSupervisorClient();
|
||
|
|
const logs = await client.readLog(offset, length);
|
||
|
|
|
||
|
|
return NextResponse.json({ logs, offset, length });
|
||
|
|
} catch (error: any) {
|
||
|
|
console.error('Supervisor main log error:', error);
|
||
|
|
return NextResponse.json(
|
||
|
|
{ error: error.message || 'Failed to fetch main log' },
|
||
|
|
{ status: 500 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// DELETE - Clear main supervisord log
|
||
|
|
export async function DELETE() {
|
||
|
|
try {
|
||
|
|
const client = createSupervisorClient();
|
||
|
|
const result = await client.clearLog();
|
||
|
|
return NextResponse.json({ success: result, message: 'Main log cleared' });
|
||
|
|
} catch (error: any) {
|
||
|
|
console.error('Supervisor clear main log error:', error);
|
||
|
|
return NextResponse.json(
|
||
|
|
{ error: error.message || 'Failed to clear main log' },
|
||
|
|
{ status: 500 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|