From 0d5e5c65a331ac9772a6df19174806aff2aac82d Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sat, 19 Apr 2025 08:53:17 -0600 Subject: [PATCH] Add /health endpoint --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index 8c1da74..8d4b7cd 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ const fs = require('fs'); const path = require('path'); const markdown = require('markdown-it')(); const ejs = require('ejs'); +const { connect } = require('http2'); const app = express(); expressWs(app); @@ -40,6 +41,19 @@ app.get("/", (req, res) => { res.render('docViewer', {title: 'Websocket Docs', htmlContent: htmlContent}); }); }); +var socketStatus; +app.get('/health', (req, res) => { + res.status(200).json({ + status: socketStatus, + connections: wsConnections.length, + uptime: process.uptime(), + messages: messages, + errCount: errCount, + startup: startup, + startTime: startTimestap, + uuid: curUUID, + }); +}); global.wsConnections = []; var roomList = []; @@ -484,6 +498,7 @@ xmpp.on("stanza", (stanza) => { }); xmpp.on("status", (status) => { + socketStatus = status; console.log(`${colors.cyan("[INFO]")} XMPP Status is ${status}`); // Broadcast a message to all connected WebSocket clients wsConnections.forEach((connection) => {