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 %>