From 06a324f9c49506846f6ad4e500a0c141e08aab14 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 16 Dec 2024 16:40:35 -0700 Subject: [PATCH] Add healthcheck API (For uptimekuma, soon:tm:) --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index d9fa56e..2cf9d4b 100644 --- a/index.js +++ b/index.js @@ -596,6 +596,19 @@ app.get("/api/v1/checkAvailability/:number", (req, res) => { }); }); +app.get("/api/healthcheck", (req, res) => { + // Check ability to connect to database with select * from routes + db.get('SELECT * FROM routes', [], (err, row) => { + if (err) { + console.error('Error checking health:', err); + res.status(500).send('Internal server error'); + return; + } + res.status(200).send('OK'); + }); +}); + + // Query to get a route app.get('/api/v1/route/:apiKey/:ani/:number', (req, res) => { const apiKey = req.params.apiKey;