MCPcopy Create free account
hub / github.com/CodeFox-Repo/codefox / GET

Function GET

frontend/src/app/api/runProject/route.ts:501–566  ·  view source on GitHub ↗
(req: Request)

Source from the content-addressed store, hash-verified

499 * GET request handler for starting a Docker container
500 */
501export async function GET(req: Request) {
502 const { searchParams } = new URL(req.url);
503 const projectPath = searchParams.get('projectPath');
504
505 if (!projectPath) {
506 return NextResponse.json(
507 { error: 'Missing required parameters' },
508 { status: 400 }
509 );
510 }
511
512 // Check if a container is already running
513 const existingContainer = runningContainers.get(projectPath);
514 if (existingContainer) {
515 // Verify container is still running
516 const isRunning = await checkContainerRunning(
517 existingContainer.containerId
518 );
519 if (isRunning) {
520 return NextResponse.json({
521 message: 'Docker container already running',
522 domain: existingContainer.domain,
523 containerId: existingContainer.containerId,
524 });
525 } else {
526 // Remove non-running container from state
527 runningContainers.delete(projectPath);
528 if (existingContainer.port) {
529 allocatedPorts.delete(existingContainer.port);
530 }
531 await saveState();
532
533 logger.info(
534 `Container ${existingContainer.containerId} is no longer running, will create a new one`
535 );
536 }
537 }
538
539 // Prevent duplicate builds
540 if (processingRequests.has(projectPath)) {
541 return NextResponse.json({
542 message: 'Container creation in progress',
543 status: 'pending',
544 });
545 }
546
547 processingRequests.add(projectPath);
548
549 try {
550 const { domain, containerId } = await runDockerContainer(projectPath);
551
552 return NextResponse.json({
553 message: 'Docker container started',
554 domain,
555 containerId,
556 });
557 } catch (error: any) {
558 logger.error(`Failed to start Docker container:`, error);

Callers

nothing calls this directly

Calls 4

checkContainerRunningFunction · 0.85
saveStateFunction · 0.85
runDockerContainerFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected