File size: 2,732 Bytes
65d3b67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2ec119
65d3b67
a2ec119
 
 
 
65d3b67
a2ec119
65d3b67
 
 
 
 
 
a2ec119
 
65d3b67
 
 
a2ec119
 
65d3b67
 
a2ec119
 
65d3b67
 
a2ec119
 
65d3b67
 
a2ec119
65d3b67
 
 
 
 
a2ec119
 
 
 
 
 
 
65d3b67
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>FastHost Dashboard</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background: #f8f9fa;
      padding: 20px;
    }
    h1 {
      color: #343a40;
    }
    .card {
      background: white;
      padding: 15px;
      margin: 10px 0;
      border-radius: 8px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    .buttons button {
      margin-right: 5px;
    }
    pre {
      background: #e9ecef;
      padding: 10px;
      max-height: 200px;
      overflow-y: auto;
    }
  </style>
</head>
<body>
  <h1>🚀 FastHost Dashboard</h1>
  <div id="projects"></div>

  <script>
    async function fetchProjects() {
      const res = await fetch('/projects');
      const data = await res.json();
      const container = document.getElementById('projects');
      container.innerHTML = '';

      data.forEach(proj => {
        const card = document.createElement('div');
        card.className = 'card';

        card.innerHTML = `
          <h3>${proj.name}</h3>
          <p>Status: <b>${proj.status}</b></p>
          <p>URL: <a href="${proj.url}" target="_blank">${proj.url}</a></p>
          <div class="buttons">
            <button onclick="stopProject('${proj.name}')">🛑 Stop</button>
            <button onclick="startProject('${proj.name}')">▶️ Start</button>
            <button onclick="pauseProject('${proj.name}')">⏸️ Pause</button>
            <button onclick="toggleLogs('${proj.name}')">📜 View Logs</button>
          </div>
          <pre id="log-${proj.name}" style="display:none"></pre>
        `;

        container.appendChild(card);
      });
    }

    async function stopProject(name) {
      await fetch(`/stop/${name}`, { method: 'POST' });
      fetchProjects();
    }

    async function startProject(name) {
      alert('Start functionality is not implemented via FastAPI yet.');
    }

    async function pauseProject(name) {
      alert('Pause functionality is not implemented via FastAPI yet.');
    }

    function toggleLogs(name) {
      const pre = document.getElementById(`log-${name}`);
      if (pre.style.display === 'none') {
        pre.style.display = 'block';
        streamLogs(name, pre);
      } else {
        pre.style.display = 'none';
      }
    }

    function streamLogs(name, target) {
      const evtSrc = new EventSource(`/logs/${name}`);
      evtSrc.onmessage = function (event) {
        target.textContent += event.data + "\n";
        target.scrollTop = target.scrollHeight;
      };
      evtSrc.onerror = () => evtSrc.close();
    }

    fetchProjects();
  </script>
</body>
</html>