From dcd6cb3d1f001bb98b2acdae9efe6f3cd04e4dc2 Mon Sep 17 00:00:00 2001 From: localhost Date: Mon, 8 Apr 2024 23:43:21 +0200 Subject: [PATCH] health checks --- index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/index.js b/index.js index da4b2ca..671c8eb 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,31 @@ const app = express() const maxRetries = 5 const platforms = ['YTSTUDIO_ANDROID', 'WEB', 'YTMUSIC_ANDROID', 'YTMUSIC', 'TV_EMBEDDED'] +app.get('/health', async (req, res) => { + try { + const urls = ['/video/sRMMwpDTs5k', '/channel/UCRijo3ddMTht_IHyNSNXpNQ', '/videos/UCRijo3ddMTht_IHyNSNXpNQ'] + + const results = await Promise.all(urls.map(async (url) => { + const response = await fetch(`http://localhost:8008${url}`); + const jsonData = await response.json(); + const status = jsonData.error ? 'unhealthy' : 'healthy'; + return { url, status }; + })); + + console.log('Health check results:', results); + + const isHealthy = results.every(result => result.status === 'healthy'); + if (isHealthy) { + res.status(200).json({ message: 'All endpoints are healthy', results }); + } else { + res.status(500).json({ error: 'Health check failed', results }); + } + } catch (error) { + console.error('Health check failed:', error.message); + res.status(500).json({ error: 'Health check failed', results: [], errorMessage: error.message }); + } +}) + app.get('/video/:id', async (req, res) => { let error = ''