Aggiunto collegamento al server
This commit is contained in:
50
plugin/tools/healthcheck.js
Normal file
50
plugin/tools/healthcheck.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const SERVICES = {
|
||||
api: 'https://api.mebboat.it/health',
|
||||
storage: 'https://storage.mebboat.it/health',
|
||||
auth: 'https://auth.mebboat.it/health',
|
||||
realtime: 'https://realtime.mebboat.it/health',
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks the health of a single service.
|
||||
* @param {string} url - Health endpoint URL
|
||||
* @returns {Promise<{ok: boolean, status: string}>}
|
||||
*/
|
||||
async function checkService(url) {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
headers: { Accept: "application/json" }
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { ok: false, status: `HTTP ${response.status}` };
|
||||
}
|
||||
|
||||
const data = await response.json().catch(() => null);
|
||||
const isOk = data?.status === "ok";
|
||||
return { ok: isOk, status: isOk ? 'online' : 'offline' };
|
||||
} catch (err) {
|
||||
return { ok: false, status: `error: ${err.message}` };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks all MEB cloud services in parallel.
|
||||
* @returns {Promise<Object>} Map of service name -> health result
|
||||
*/
|
||||
async function checkAllServices() {
|
||||
const entries = Object.entries(SERVICES);
|
||||
const results = await Promise.all(
|
||||
entries.map(async ([name, url]) => {
|
||||
const result = await checkService(url);
|
||||
return [name, result];
|
||||
})
|
||||
);
|
||||
return Object.fromEntries(results);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
SERVICES,
|
||||
checkService,
|
||||
checkAllServices
|
||||
};
|
||||
Reference in New Issue
Block a user