feat(logging): add comprehensive logging to all API routes (Phase 4)

Applied withLogging() wrapper to all 24 API routes for consistent logging:

Process Control Routes:
- Start/stop/restart individual processes
- Start-all/stop-all/restart-all batch operations

Signal Routes:
- Signal individual processes
- Signal all processes
- Signal process groups

Group Management Routes:
- Start/stop/restart process groups
- Signal operations for groups

Configuration Routes:
- Get all configs (GET)
- Reload configuration (POST)
- Add/remove process groups (POST/DELETE)

Log Routes:
- Read main supervisord log
- Read process stdout/stderr logs
- Clear process logs (individual and all)

System Routes:
- Get system info
- Get all processes info
- Get individual process info
- Send stdin to process

All routes now include:
- Request/response logging with timing
- Automatic error handling and correlation IDs
- X-Request-ID header propagation
- Consistent metadata in responses

Also fixed Next.js 16 deprecation:
- Moved experimental.serverComponentsExternalPackages to serverExternalPackages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-23 20:53:23 +01:00
parent b252a0b3bf
commit d592b58b75
26 changed files with 391 additions and 502 deletions

View File

@@ -1,9 +1,8 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
// POST - Add a process group export const POST = withLogging(async (request: NextRequest) => {
export async function POST(request: NextRequest) {
try {
const body = await request.json(); const body = await request.json();
const { name } = body; const { name } = body;
@@ -20,19 +19,11 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ return NextResponse.json({
success: result, success: result,
message: `Process group '${name}' added successfully`, message: `Process group '${name}' added successfully`,
groupName: name,
}); });
} catch (error: any) { }, 'addProcessGroup');
console.error('Supervisor add process group error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to add process group' },
{ status: 500 }
);
}
}
// DELETE - Remove a process group export const DELETE = withLogging(async (request: NextRequest) => {
export async function DELETE(request: NextRequest) {
try {
const body = await request.json(); const body = await request.json();
const { name } = body; const { name } = body;
@@ -49,12 +40,6 @@ export async function DELETE(request: NextRequest) {
return NextResponse.json({ return NextResponse.json({
success: result, success: result,
message: `Process group '${name}' removed successfully`, message: `Process group '${name}' removed successfully`,
groupName: name,
}); });
} catch (error: any) { }, 'removeProcessGroup');
console.error('Supervisor remove process group error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to remove process group' },
{ status: 500 }
);
}
}

View File

@@ -1,21 +1,14 @@
import { NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
// POST - Reload configuration export const POST = withLogging(async (request: NextRequest) => {
export async function POST() {
try {
const client = createSupervisorClient(); const client = createSupervisorClient();
const result = await client.reloadConfig(); const result = await client.reloadConfig();
return NextResponse.json({ return NextResponse.json({
success: true, success: true,
message: 'Configuration reloaded', message: 'Configuration reloaded',
result, result,
}); });
} catch (error: any) { }, 'reloadConfig');
console.error('Supervisor reload config error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to reload configuration' },
{ status: 500 }
);
}
}

View File

@@ -1,17 +1,9 @@
import { NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
// GET - Get all process configurations export const GET = withLogging(async (request: NextRequest) => {
export async function GET() {
try {
const client = createSupervisorClient(); const client = createSupervisorClient();
const configs = await client.getAllConfigInfo(); const configs = await client.getAllConfigInfo();
return NextResponse.json(configs); return NextResponse.json(configs);
} catch (error: any) { }, 'getAllConfigInfo');
console.error('Supervisor get config error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to fetch configuration' },
{ status: 500 }
);
}
}

View File

@@ -1,5 +1,7 @@
import { NextRequest } from 'next/server'; import { NextRequest } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { createApiLogger, generateRequestId } from '@/lib/utils/api-logger';
import { formatError } from '@/lib/utils/logger';
export const dynamic = 'force-dynamic'; export const dynamic = 'force-dynamic';
@@ -8,9 +10,16 @@ export const dynamic = 'force-dynamic';
* Polls supervisor every 2 seconds and sends state changes to clients * Polls supervisor every 2 seconds and sends state changes to clients
*/ */
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
const requestId = generateRequestId();
const logger = createApiLogger(request, 'SSE-Events');
const encoder = new TextEncoder(); const encoder = new TextEncoder();
let intervalId: NodeJS.Timeout | null = null; let intervalId: NodeJS.Timeout | null = null;
let previousState: string | null = null; let previousState: string | null = null;
let pollCount = 0;
let stateChangeCount = 0;
logger.info({ requestId }, 'SSE connection initiated');
const stream = new ReadableStream({ const stream = new ReadableStream({
async start(controller) { async start(controller) {
@@ -22,9 +31,13 @@ export async function GET(request: NextRequest) {
// Send initial connection message // Send initial connection message
sendEvent('connected', { timestamp: Date.now() }); sendEvent('connected', { timestamp: Date.now() });
logger.debug({ requestId }, 'SSE connected event sent');
// Poll supervisor for state changes // Poll supervisor for state changes
const pollSupervisor = async () => { const pollSupervisor = async () => {
pollCount++;
const pollStartTime = Date.now();
try { try {
const client = createSupervisorClient(); const client = createSupervisorClient();
const processes = await client.getAllProcessInfo(); const processes = await client.getAllProcessInfo();
@@ -41,17 +54,40 @@ export async function GET(request: NextRequest) {
// Send update if state changed // Send update if state changed
if (currentState !== previousState) { if (currentState !== previousState) {
stateChangeCount++;
sendEvent('process-update', { sendEvent('process-update', {
processes, processes,
timestamp: Date.now(), timestamp: Date.now(),
}); });
logger.info({
requestId,
pollCount,
stateChangeCount,
processCount: processes.length,
duration: Date.now() - pollStartTime,
}, `Process state change detected (change #${stateChangeCount})`);
previousState = currentState; previousState = currentState;
} }
// Send heartbeat every poll // Send heartbeat every poll (reduced logging - only log every 10th heartbeat)
sendEvent('heartbeat', { timestamp: Date.now() }); sendEvent('heartbeat', { timestamp: Date.now() });
if (pollCount % 10 === 0) {
logger.debug({
requestId,
pollCount,
stateChangeCount,
duration: Date.now() - pollStartTime,
}, `SSE heartbeat #${pollCount}`);
}
} catch (error: any) { } catch (error: any) {
console.error('SSE polling error:', error); const errorInfo = formatError(error);
logger.error({
requestId,
pollCount,
error: errorInfo,
duration: Date.now() - pollStartTime,
}, `SSE polling error: ${errorInfo.message}`);
sendEvent('error', { sendEvent('error', {
message: error.message || 'Failed to fetch process state', message: error.message || 'Failed to fetch process state',
timestamp: Date.now(), timestamp: Date.now(),
@@ -70,6 +106,12 @@ export async function GET(request: NextRequest) {
if (intervalId) { if (intervalId) {
clearInterval(intervalId); clearInterval(intervalId);
} }
logger.info({
requestId,
pollCount,
stateChangeCount,
duration: Date.now() - Date.now(),
}, 'SSE connection closed');
}, },
}); });
@@ -79,6 +121,7 @@ export async function GET(request: NextRequest) {
'Cache-Control': 'no-cache, no-transform', 'Cache-Control': 'no-cache, no-transform',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'X-Accel-Buffering': 'no', // Disable nginx buffering 'X-Accel-Buffering': 'no', // Disable nginx buffering
'X-Request-ID': requestId,
}, },
}); });
} }

View File

@@ -1,13 +1,12 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
// POST - Restart all processes in a group (stop then start) export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
export async function POST(request: NextRequest, { params }: RouteParams) {
try {
const { name } = await params; const { name } = await params;
const body = await request.json().catch(() => ({})); const body = await request.json().catch(() => ({}));
const wait = body.wait ?? true; const wait = body.wait ?? true;
@@ -24,12 +23,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
success: true, success: true,
message: `Restarted process group: ${name}`, message: `Restarted process group: ${name}`,
results, results,
groupName: name,
wait,
}); });
} catch (error: any) { }, 'restartProcessGroup');
console.error('Supervisor restart process group error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to restart process group' },
{ status: 500 }
);
}
}

View File

@@ -1,13 +1,12 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
// POST - Send signal to all processes in a group export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
export async function POST(request: NextRequest, { params }: RouteParams) {
try {
const { name } = await params; const { name } = await params;
const body = await request.json(); const body = await request.json();
const { signal } = body; const { signal } = body;
@@ -26,12 +25,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
success: true, success: true,
message: `Signal ${signal} sent to group ${name}`, message: `Signal ${signal} sent to group ${name}`,
results, results,
groupName: name,
signal,
}); });
} catch (error: any) { }, 'signalProcessGroup');
console.error('Supervisor signal process group error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to send signal to process group' },
{ status: 500 }
);
}
}

View File

@@ -1,13 +1,12 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
// POST - Start all processes in a group export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
export async function POST(request: NextRequest, { params }: RouteParams) {
try {
const { name } = await params; const { name } = await params;
const body = await request.json().catch(() => ({})); const body = await request.json().catch(() => ({}));
const wait = body.wait ?? true; const wait = body.wait ?? true;
@@ -19,12 +18,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
success: true, success: true,
message: `Started process group: ${name}`, message: `Started process group: ${name}`,
results, results,
groupName: name,
wait,
}); });
} catch (error: any) { }, 'startProcessGroup');
console.error('Supervisor start process group error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to start process group' },
{ status: 500 }
);
}
}

View File

@@ -1,13 +1,12 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
// POST - Stop all processes in a group export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
export async function POST(request: NextRequest, { params }: RouteParams) {
try {
const { name } = await params; const { name } = await params;
const body = await request.json().catch(() => ({})); const body = await request.json().catch(() => ({}));
const wait = body.wait ?? true; const wait = body.wait ?? true;
@@ -19,12 +18,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
success: true, success: true,
message: `Stopped process group: ${name}`, message: `Stopped process group: ${name}`,
results, results,
groupName: name,
wait,
}); });
} catch (error: any) { }, 'stopProcessGroup');
console.error('Supervisor stop process group error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to stop process group' },
{ status: 500 }
);
}
}

View File

@@ -1,11 +1,10 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
export const dynamic = 'force-dynamic'; export const dynamic = 'force-dynamic';
// GET main supervisord log export const GET = withLogging(async (request: NextRequest) => {
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams; const searchParams = request.nextUrl.searchParams;
const offset = parseInt(searchParams.get('offset') || '-4096', 10); const offset = parseInt(searchParams.get('offset') || '-4096', 10);
const length = parseInt(searchParams.get('length') || '4096', 10); const length = parseInt(searchParams.get('length') || '4096', 10);
@@ -14,26 +13,11 @@ export async function GET(request: NextRequest) {
const logs = await client.readLog(offset, length); const logs = await client.readLog(offset, length);
return NextResponse.json({ logs, offset, length }); return NextResponse.json({ logs, offset, length });
} catch (error: any) { }, 'readMainLog');
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 const DELETE = withLogging(async (request: NextRequest) => {
export async function DELETE() {
try {
const client = createSupervisorClient(); const client = createSupervisorClient();
const result = await client.clearLog(); const result = await client.clearLog();
return NextResponse.json({ success: result, message: 'Main log cleared' }); return NextResponse.json({ success: result, message: 'Main log cleared' });
} catch (error: any) { }, 'clearMainLog');
console.error('Supervisor clear main log error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to clear main log' },
{ status: 500 }
);
}
}

View File

@@ -1,22 +1,20 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
// DELETE - Clear process logs (both stdout and stderr) export const DELETE = withLogging(async (request: NextRequest, { params }: RouteParams) => {
export async function DELETE(request: NextRequest, { params }: RouteParams) {
try {
const { name } = await params; const { name } = await params;
const client = createSupervisorClient(); const client = createSupervisorClient();
const result = await client.clearProcessLogs(name); const result = await client.clearProcessLogs(name);
return NextResponse.json({ success: result, message: `Logs cleared for ${name}` });
} catch (error: any) { return NextResponse.json({
console.error('Supervisor clear process logs error:', error); success: result,
return NextResponse.json( message: `Logs cleared for ${name}`,
{ error: error.message || 'Failed to clear process logs' }, processName: name,
{ status: 500 } });
); }, 'clearProcessLogs');
}
}

View File

@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
export const dynamic = 'force-dynamic'; export const dynamic = 'force-dynamic';
@@ -7,8 +8,7 @@ interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
export async function GET(request: NextRequest, { params }: RouteParams) { export const GET = withLogging(async (request: NextRequest, { params }: RouteParams) => {
try {
const { name } = await params; const { name } = await params;
const searchParams = request.nextUrl.searchParams; const searchParams = request.nextUrl.searchParams;
const offset = parseInt(searchParams.get('offset') || '-4096', 10); const offset = parseInt(searchParams.get('offset') || '-4096', 10);
@@ -16,12 +16,6 @@ export async function GET(request: NextRequest, { params }: RouteParams) {
const client = createSupervisorClient(); const client = createSupervisorClient();
const logs = await client.tailProcessStderrLog(name, offset, length); const logs = await client.tailProcessStderrLog(name, offset, length);
return NextResponse.json(logs); return NextResponse.json(logs);
} catch (error: any) { }, 'readProcessStderr');
console.error('Supervisor stderr log error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to fetch stderr logs' },
{ status: 500 }
);
}
}

View File

@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
export const dynamic = 'force-dynamic'; export const dynamic = 'force-dynamic';
@@ -7,8 +8,7 @@ interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
export async function GET(request: NextRequest, { params }: RouteParams) { export const GET = withLogging(async (request: NextRequest, { params }: RouteParams) => {
try {
const { name } = await params; const { name } = await params;
const searchParams = request.nextUrl.searchParams; const searchParams = request.nextUrl.searchParams;
const offset = parseInt(searchParams.get('offset') || '-4096', 10); const offset = parseInt(searchParams.get('offset') || '-4096', 10);
@@ -16,12 +16,6 @@ export async function GET(request: NextRequest, { params }: RouteParams) {
const client = createSupervisorClient(); const client = createSupervisorClient();
const logs = await client.tailProcessStdoutLog(name, offset, length); const logs = await client.tailProcessStdoutLog(name, offset, length);
return NextResponse.json(logs); return NextResponse.json(logs);
} catch (error: any) { }, 'readProcessStdout');
console.error('Supervisor stdout log error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to fetch stdout logs' },
{ status: 500 }
);
}
}

View File

@@ -1,21 +1,20 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
export async function POST(request: NextRequest, { params }: RouteParams) { export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
try {
const { name } = await params; const { name } = await params;
const client = createSupervisorClient(); const client = createSupervisorClient();
const result = await client.restartProcess(name); const result = await client.restartProcess(name);
return NextResponse.json({ success: result, message: `Process ${name} restarted` });
} catch (error: any) { return NextResponse.json({
console.error('Supervisor restart process error:', error); success: result,
return NextResponse.json( message: `Process ${name} restarted`,
{ error: error.message || 'Failed to restart process' }, processName: name,
{ status: 500 } });
); }, 'restartProcess');
}
}

View File

@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
export const dynamic = 'force-dynamic'; export const dynamic = 'force-dynamic';
@@ -7,17 +8,11 @@ interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
export async function GET(request: NextRequest, { params }: RouteParams) { export const GET = withLogging(async (request: NextRequest, { params }: RouteParams) => {
try {
const { name } = await params; const { name } = await params;
const client = createSupervisorClient(); const client = createSupervisorClient();
const processInfo = await client.getProcessInfo(name); const processInfo = await client.getProcessInfo(name);
return NextResponse.json(processInfo); return NextResponse.json(processInfo);
} catch (error: any) { }, 'getProcessInfo');
console.error('Supervisor process info error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to fetch process info' },
{ status: 500 }
);
}
}

View File

@@ -1,13 +1,12 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
// POST - Send signal to a process export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
export async function POST(request: NextRequest, { params }: RouteParams) {
try {
const { name } = await params; const { name } = await params;
const body = await request.json(); const body = await request.json();
const { signal } = body; const { signal } = body;
@@ -25,12 +24,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
return NextResponse.json({ return NextResponse.json({
success: result, success: result,
message: `Signal ${signal} sent to ${name}`, message: `Signal ${signal} sent to ${name}`,
processName: name,
signal,
}); });
} catch (error: any) { }, 'signalProcess');
console.error('Supervisor signal process error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to send signal to process' },
{ status: 500 }
);
}
}

View File

@@ -1,24 +1,23 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
export async function POST(request: NextRequest, { params }: RouteParams) { export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
try {
const { name } = await params; const { name } = await params;
const body = await request.json().catch(() => ({})); const body = await request.json().catch(() => ({}));
const wait = body.wait !== undefined ? body.wait : true; const wait = body.wait !== undefined ? body.wait : true;
const client = createSupervisorClient(); const client = createSupervisorClient();
const result = await client.startProcess(name, wait); const result = await client.startProcess(name, wait);
return NextResponse.json({ success: result, message: `Process ${name} started` });
} catch (error: any) { return NextResponse.json({
console.error('Supervisor start process error:', error); success: result,
return NextResponse.json( message: `Process ${name} started`,
{ error: error.message || 'Failed to start process' }, processName: name,
{ status: 500 } wait,
); });
} }, 'startProcess');
}

View File

@@ -1,13 +1,12 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
// POST - Send input to process stdin export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
export async function POST(request: NextRequest, { params }: RouteParams) {
try {
const { name } = await params; const { name } = await params;
const body = await request.json(); const body = await request.json();
const { chars } = body; const { chars } = body;
@@ -25,12 +24,6 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
return NextResponse.json({ return NextResponse.json({
success: result, success: result,
message: `Input sent to ${name}`, message: `Input sent to ${name}`,
processName: name,
}); });
} catch (error: any) { }, 'sendProcessStdin');
console.error('Supervisor send stdin error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to send input to process' },
{ status: 500 }
);
}
}

View File

@@ -1,24 +1,23 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
interface RouteParams { interface RouteParams {
params: Promise<{ name: string }>; params: Promise<{ name: string }>;
} }
export async function POST(request: NextRequest, { params }: RouteParams) { export const POST = withLogging(async (request: NextRequest, { params }: RouteParams) => {
try {
const { name } = await params; const { name } = await params;
const body = await request.json().catch(() => ({})); const body = await request.json().catch(() => ({}));
const wait = body.wait !== undefined ? body.wait : true; const wait = body.wait !== undefined ? body.wait : true;
const client = createSupervisorClient(); const client = createSupervisorClient();
const result = await client.stopProcess(name, wait); const result = await client.stopProcess(name, wait);
return NextResponse.json({ success: result, message: `Process ${name} stopped` });
} catch (error: any) { return NextResponse.json({
console.error('Supervisor stop process error:', error); success: result,
return NextResponse.json( message: `Process ${name} stopped`,
{ error: error.message || 'Failed to stop process' }, processName: name,
{ status: 500 } wait,
); });
} }, 'stopProcess');
}

View File

@@ -1,21 +1,14 @@
import { NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
// POST - Clear all process logs export const POST = withLogging(async (request: NextRequest) => {
export async function POST() {
try {
const client = createSupervisorClient(); const client = createSupervisorClient();
const results = await client.clearAllProcessLogs(); const results = await client.clearAllProcessLogs();
return NextResponse.json({ return NextResponse.json({
success: true, success: true,
message: 'All process logs cleared', message: 'All process logs cleared',
results results,
}); });
} catch (error: any) { }, 'clearAllProcessLogs');
console.error('Supervisor clear all logs error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to clear all logs' },
{ status: 500 }
);
}
}

View File

@@ -1,9 +1,8 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
// POST - Restart all processes (stop then start) export const POST = withLogging(async (request: NextRequest) => {
export async function POST(request: NextRequest) {
try {
const body = await request.json().catch(() => ({})); const body = await request.json().catch(() => ({}));
const wait = body.wait ?? true; const wait = body.wait ?? true;
@@ -19,12 +18,6 @@ export async function POST(request: NextRequest) {
success: true, success: true,
message: 'Restarted all processes', message: 'Restarted all processes',
results, results,
wait,
}); });
} catch (error: any) { }, 'restartAllProcesses');
console.error('Supervisor restart all processes error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to restart all processes' },
{ status: 500 }
);
}
}

View File

@@ -1,18 +1,12 @@
import { NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
export const dynamic = 'force-dynamic'; export const dynamic = 'force-dynamic';
export async function GET() { export const GET = withLogging(async (request: NextRequest) => {
try {
const client = createSupervisorClient(); const client = createSupervisorClient();
const processes = await client.getAllProcessInfo(); const processes = await client.getAllProcessInfo();
return NextResponse.json(processes); return NextResponse.json(processes);
} catch (error: any) { }, 'getAllProcessInfo');
console.error('Supervisor processes error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to fetch processes' },
{ status: 500 }
);
}
}

View File

@@ -1,9 +1,8 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
// POST - Send signal to all processes export const POST = withLogging(async (request: NextRequest) => {
export async function POST(request: NextRequest) {
try {
const body = await request.json(); const body = await request.json();
const { signal } = body; const { signal } = body;
@@ -21,12 +20,6 @@ export async function POST(request: NextRequest) {
success: true, success: true,
message: `Signal ${signal} sent to all processes`, message: `Signal ${signal} sent to all processes`,
results, results,
signal,
}); });
} catch (error: any) { }, 'signalAllProcesses');
console.error('Supervisor signal all processes error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to send signal to all processes' },
{ status: 500 }
);
}
}

View File

@@ -1,9 +1,8 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
// POST - Start all processes export const POST = withLogging(async (request: NextRequest) => {
export async function POST(request: NextRequest) {
try {
const body = await request.json().catch(() => ({})); const body = await request.json().catch(() => ({}));
const wait = body.wait ?? true; const wait = body.wait ?? true;
@@ -14,12 +13,6 @@ export async function POST(request: NextRequest) {
success: true, success: true,
message: 'Started all processes', message: 'Started all processes',
results, results,
wait,
}); });
} catch (error: any) { }, 'startAllProcesses');
console.error('Supervisor start all processes error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to start all processes' },
{ status: 500 }
);
}
}

View File

@@ -1,9 +1,8 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
// POST - Stop all processes export const POST = withLogging(async (request: NextRequest) => {
export async function POST(request: NextRequest) {
try {
const body = await request.json().catch(() => ({})); const body = await request.json().catch(() => ({}));
const wait = body.wait ?? true; const wait = body.wait ?? true;
@@ -14,12 +13,6 @@ export async function POST(request: NextRequest) {
success: true, success: true,
message: 'Stopped all processes', message: 'Stopped all processes',
results, results,
wait,
}); });
} catch (error: any) { }, 'stopAllProcesses');
console.error('Supervisor stop all processes error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to stop all processes' },
{ status: 500 }
);
}
}

View File

@@ -1,18 +1,12 @@
import { NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { createSupervisorClient } from '@/lib/supervisor/client'; import { createSupervisorClient } from '@/lib/supervisor/client';
import { withLogging } from '@/lib/utils/api-logger';
export const dynamic = 'force-dynamic'; export const dynamic = 'force-dynamic';
export async function GET() { export const GET = withLogging(async (request: NextRequest) => {
try {
const client = createSupervisorClient(); const client = createSupervisorClient();
const systemInfo = await client.getSystemInfo(); const systemInfo = await client.getSystemInfo();
return NextResponse.json(systemInfo); return NextResponse.json(systemInfo);
} catch (error: any) { }, 'getSystemInfo');
console.error('Supervisor system info error:', error);
return NextResponse.json(
{ error: error.message || 'Failed to fetch system info' },
{ status: 500 }
);
}
}

View File

@@ -5,9 +5,7 @@ const nextConfig: NextConfig = {
output: 'standalone', output: 'standalone',
// Turbopack configuration (Next.js 16+) // Turbopack configuration (Next.js 16+)
turbopack: {}, turbopack: {},
experimental: { serverExternalPackages: ['pino', 'pino-pretty'],
serverComponentsExternalPackages: ['pino', 'pino-pretty'],
},
}; };
export default nextConfig; export default nextConfig;