commit inicial

This commit is contained in:
Luiz F Picolo 2023-06-12 11:16:15 -04:00
commit eead1cca3d

49
index.js Normal file
View File

@ -0,0 +1,49 @@
const axios = require('axios');
function checkSiteStatus(site) {
return Promise.race([
axios.get(`https://${site}/api/v1/instance`),
new Promise((resolve, reject) => {
setTimeout(() => reject(new Error('Tempo de espera excedido')), 30000);
})
])
.then(response => {
return { site, status: 'online' };
})
.catch(error => {
return { site, status: 'offline' };
});
}
async function fetchSitesFromAPI() {
try {
const response = await axios.get('https://mastodon.social/api/v1/instance/peers');
return response.data;
} catch (error) {
console.error('Erro ao buscar sites da API:', error.message);
return [];
}
}
async function checkAllSitesStatus() {
const sites = await fetchSitesFromAPI();
if (sites.length === 0) {
console.log('Nenhum site encontrado na API.');
return;
}
const results = [];
for (const site of sites) {
try {
const result = await checkSiteStatus(site);
console.log(`${result.site} está ${result.status}.`);
results.push(result);
} catch (error) {
console.error(`Erro ao verificar o status de ${site}:`, error.message);
}
}
}
checkAllSitesStatus();