From 61685b687b89eead4a24b8d3097156aa8a3716f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Fri, 29 May 2026 22:33:40 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20healthz=20=D0=B2=D1=81=D0=B5=D0=B3=D0=B4?= =?UTF-8?q?=D0=B0=20200,=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D1=80=D0=B5=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 25 ++++++++++++++----------- views/index.ejs | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/server.js b/server.js index 5c2138b..0525762 100644 --- a/server.js +++ b/server.js @@ -16,19 +16,22 @@ app.use(express.static(path.join(__dirname, 'public'))); // Парсинг форм app.use(express.urlencoded({ extended: true })); -// Health check (для nubes_nodejs) -app.get('/healthz', async (req, res) => { - try { - await checkConnection(); - res.status(200).send('OK'); - } catch (e) { - res.status(500).send('DB error'); - } +// Health check — всегда 200 если сервер жив. +// Статус БД проверяется отдельно. +app.get('/healthz', (req, res) => { + res.status(200).send('OK'); }); -// Главная страница -app.get('/', (req, res) => { - res.render('index', { title: 'IP WhiteList' }); +// Главная — показывает реальный статус БД +app.get('/', async (req, res) => { + let dbStatus = 'неизвестно'; + try { + await checkConnection(); + dbStatus = 'подключена'; + } catch (e) { + dbStatus = 'ошибка: ' + e.message; + } + res.render('index', { title: 'IP WhiteList', dbStatus }); }); // Не падаем если БД недоступна — healthcheck покажет статус diff --git a/views/index.ejs b/views/index.ejs index 36527cd..82f7452 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -8,6 +8,6 @@

<%= title %>

-

Сервис работает. БД подключена.

+

Сервис работает. БД: <%= dbStatus %>