From 8242ade01b9b2abb1ff7cde0d32023d7f925d851 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Tue, 9 Sep 2025 13:14:11 -0400 Subject: [PATCH] mon: add alternative to /healthcheck Some monitoring services want a system to look like it's failing hard instead of a system being able to report that it's failing successfully. This commit adds an alternative to healthcheck that throws 500 when any service is failing, as though reporting such depended on the services working, to appease these monitoring services and their semantically incorrect nature of operation. This commit message sets the precedent for "mon:" as a conventional commit style prefix for changes related to system health and monitoring. --- .../healthcheck-abusing-http-status-codes.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/backend/src/routers/healthcheck-abusing-http-status-codes.js diff --git a/src/backend/src/routers/healthcheck-abusing-http-status-codes.js b/src/backend/src/routers/healthcheck-abusing-http-status-codes.js new file mode 100644 index 000000000..ba607d929 --- /dev/null +++ b/src/backend/src/routers/healthcheck-abusing-http-status-codes.js @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2025-present Puter Technologies Inc. + * + * This file is part of Puter. + * + * Puter is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +"use strict" +const express = require('express'); +const router = new express.Router(); + +// This endpoint is identical to /healthcheck except it reports status 500 when +// any service is failing, as though reporting such depended on the services +// working. +router.get('/healthcheck-abusing-http-status-codes', async (req, res) => { + const svc_serverHealth = req.services.get('server-health'); + + const status = await svc_serverHealth.get_status(); + res.status(status.ok ? 200 : 500).json(status); +}) +module.exports = router