Skip to content

Commit

Permalink
Update code (human)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrLetsplay2003 committed Oct 13, 2024
1 parent db9ecff commit ffc23ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cringe Studios Status</title>
<link rel="stylesheet" href="style.css">
<meta http-equiv="refresh" content="30">
</head>

<body>
Expand Down
34 changes: 12 additions & 22 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ function updateStatus(serverData) {

const serverSection = document.createElement('div');
serverSection.classList.add('server-section');

if (!serverData.services) {
serverSection.innerHTML = `<h2>${serverData.server} unavailable</h2>`;
statusEl.appendChild(serverSection);
return;
}

serverSection.innerHTML = `<h2>${serverData.server}</h2>`;

const servicesList = document.createElement('ul');
Expand All @@ -42,25 +49,8 @@ function updateStatus(serverData) {
statusEl.appendChild(serverSection);
}

// Assuming the API response now includes a "server" property for each service
Promise.all(servers.map(server => fetch(server.url)
.then(response => response.json())
.catch(error => {
console.error(`Error fetching status from ${server.url}:`, error);
return {
server: server.name,
services: []
};
})
.then(data => ({ ...data, server: server.name }))))
.then(responses => {
const mergedData = responses.reduce((acc, data) => {
acc.time = data.time;
acc.services = [...acc.services, ...data.services];
return acc;
}, { services: [] });

// Update the status page for each server individually
mergedData.services.forEach(updateStatus);
})
.catch(error => console.error('Error fetching overall status:', error));
for (let server of servers) {
fetch(server.url)
.then(data => updateStatus({ ...data, server: server.name }))
.error(a => updateStatus({ server: server.name }));
}

0 comments on commit ffc23ba

Please sign in to comment.