chore: initial commit of Server Configs
This commit is contained in:
70
httpserver/data/check-status.js
Normal file
70
httpserver/data/check-status.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* check-status.js
|
||||
* Pings all service URLs and updates services-data.json.
|
||||
* Then re-embeds the data into services-loader.js so file:// works.
|
||||
*
|
||||
* Usage: node check-status.js
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const DATA_FILE = path.join(__dirname, 'services-data.json');
|
||||
const LOADER_FILE = path.join(__dirname, 'services-loader.js');
|
||||
const INLINE_START = '// === INLINE DATA — sync with services-data.json ===';
|
||||
const INLINE_END = '// === END INLINE DATA ===';
|
||||
|
||||
async function checkServices() {
|
||||
console.log('--- Service Status Check Started ---');
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(fs.readFileSync(DATA_FILE, 'utf8'));
|
||||
} catch (err) {
|
||||
console.error('Error reading data file:', err);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const service of data.services) {
|
||||
process.stdout.write(`Checking ${service.name}... `);
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 5000);
|
||||
const res = await fetch(service.url, {
|
||||
signal: controller.signal,
|
||||
method: 'HEAD',
|
||||
headers: { 'User-Agent': 'Status-Checker/1.0' }
|
||||
});
|
||||
clearTimeout(timeout);
|
||||
if (res.status === 200 || res.status === 201) {
|
||||
console.log('\x1b[32mUP\x1b[0m (' + res.status + ')');
|
||||
delete service.status;
|
||||
} else {
|
||||
console.log('\x1b[33mDOWN\x1b[0m (' + res.status + ')');
|
||||
service.status = 'maintenance';
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('\x1b[31mOFFLINE\x1b[0m (' + err.message + ')');
|
||||
service.status = 'maintenance';
|
||||
}
|
||||
}
|
||||
|
||||
// Write updated services-data.json
|
||||
fs.writeFileSync(DATA_FILE, JSON.stringify(data, null, 2), 'utf8');
|
||||
console.log('\n✓ services-data.json updated\n');
|
||||
|
||||
// Sync embedded data into services-loader.js
|
||||
let loader = fs.readFileSync(LOADER_FILE, 'utf8');
|
||||
const startIdx = loader.indexOf(INLINE_START);
|
||||
const endIdx = loader.indexOf(INLINE_END);
|
||||
if (startIdx === -1 || endIdx === -1) {
|
||||
console.error('Could not find INLINE DATA markers in services-loader.js');
|
||||
return;
|
||||
}
|
||||
const before = loader.substring(0, startIdx);
|
||||
const after = loader.substring(endIdx + INLINE_END.length);
|
||||
const newLine = `${INLINE_START}\nconst SERVICES_EMBEDDED = ${JSON.stringify(data)};\n${INLINE_END}`;
|
||||
fs.writeFileSync(LOADER_FILE, before + newLine + after, 'utf8');
|
||||
console.log('✓ services-loader.js inline data synced');
|
||||
console.log('--- Done ---');
|
||||
}
|
||||
|
||||
checkServices();
|
||||
Reference in New Issue
Block a user