36 lines
868 B
TypeScript
Raw Normal View History

import { NextResponse } from 'next/server';
import { startGateway, stopGateway, restartGateway } from '@/lib/openclaw';
export async function POST(request: Request) {
try {
const { action } = await request.json();
if (!action || !['start', 'stop', 'restart'].includes(action)) {
return NextResponse.json(
{ error: 'Invalid action. Must be start, stop, or restart' },
{ status: 400 }
);
}
let result;
switch (action) {
case 'start':
result = await startGateway();
break;
case 'stop':
result = await stopGateway();
break;
case 'restart':
result = await restartGateway();
break;
}
return NextResponse.json(result);
} catch (error) {
return NextResponse.json(
{ error: (error as Error).message },
{ status: 500 }
);
}
}