Zum Hauptinhalt springen
Aktuellen Status und Gesundheits-Informationen der aktiven Sandbox abrufen.

Endpunkt

GET /api/sandbox-status
Keine Request-Parameter erforderlich. Gibt Informationen über die aktuell aktive Sandbox zurück.

Antwort

success
boolean
Ob die Statusprüfung erfolgreich war.
active
boolean
Ob eine Sandbox existiert.
healthy
boolean
Ob die Sandbox antwortet und funktionsfähig ist.
sandboxData
object
Detaillierte Sandbox-Informationen:
  • sandboxId: Eindeutiger Identifikator
  • url: Vorschau-URL
  • filesTracked: Array bekannter Dateien
  • lastHealthCheck: Zeitstempel der letzten Prüfung
message
string
Lesbare Status-Beschreibung.

Beispiel-Anfrage

curl http://app.seemodo.ai/api/sandbox-status

Aktiv und gesund

{
  "success": true,
  "active": true,
  "healthy": true,
  "sandboxData": {
    "sandboxId": "modal-sandbox-1234",
    "url": "https://seemodo--sandbox-1234.modal.run",
    "filesTracked": [
      "src/App.tsx",
      "src/main.jsx",
      "src/index.css",
      "src/pages/dashboard.tsx"
    ],
    "lastHealthCheck": "2024-01-15T10:30:00.000Z"
  },
  "message": "Sandbox ist aktiv und gesund"
}

Sandbox existiert aber ist nicht gesund

{
  "success": true,
  "active": true,
  "healthy": false,
  "sandboxData": null,
  "message": "Sandbox existiert aber antwortet nicht"
}

Keine aktive Sandbox

{
  "success": true,
  "active": false,
  "healthy": false,
  "sandboxData": null,
  "message": "Keine aktive Sandbox"
}

Verwendung in Anwendungen

async function checkSandboxHealth() {
  const response = await fetch('/api/sandbox-status');
  const status = await response.json();
  
  if (!status.active) {
    // Neue Sandbox erstellen
    await createSandbox();
    return;
  }
  
  if (!status.healthy) {
    // Sandbox existiert aber antwortet nicht - neu erstellen
    await killSandbox(status.sandboxData?.sandboxId);
    await createSandbox();
    return;
  }
  
  // Sandbox ist bereit zur Nutzung
  return status.sandboxData;
}

Gesundheitsprüfungs-Flow

Polling auf Bereitschaft

Beim Warten bis Sandbox bereit ist:
async function waitForSandbox(maxAttempts = 30) {
  for (let i = 0; i < maxAttempts; i++) {
    const response = await fetch('/api/sandbox-status');
    const status = await response.json();
    
    if (status.active && status.healthy) {
      return status.sandboxData;
    }
    
    // 2 Sekunden zwischen Prüfungen warten
    await new Promise(resolve => setTimeout(resolve, 2000));
  }
  
  throw new Error('Sandbox wurde nicht bereit');
}

Verwandte Endpunkte

EndpunktBeschreibung
POST /api/create-ai-sandbox-v2Neue Sandbox erstellen
GET /api/get-sandbox-filesDateien in Sandbox auflisten
POST /api/kill-sandboxSandbox beenden
POST /api/restart-viteDev-Server neustarten