From 932e5ca5b6f8719fcdc288c0c8cfb1b8ea7b042d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Thu, 9 Jul 2026 10:37:32 +0400 Subject: [PATCH] =?UTF-8?q?Fix:=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B0=D1=83?= =?UTF-8?q?=D1=82=20=D1=81=20=D0=B4=D0=B8=D0=B0=D0=B3=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=D0=BA=D0=BE=D0=B9=20PG=20(URL=20+=20=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=83=D1=81=20=D0=91=D0=94).=20=D0=92=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D1=8F=200.1.25?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 3b8a9b8..83d44b3 100644 --- a/server.js +++ b/server.js @@ -57,11 +57,25 @@ app.use(cookieParser()); async function start() { const auth = await initAuth(); - // ── Стоп-кран: если запрос висит > 10 сек — обрываем с ошибкой ─────── + // ── Стоп-кран: если запрос висит > 10 сек — проверяем PG и показываем детали app.use((req, res, next) => { - const timer = setTimeout(() => { + const timer = setTimeout(async () => { if (!res.headersSent) { - res.status(503).type('html').send('

Сервис временно недоступен

Превышено время ожидания

'); + let diag = ''; + try { + const { pool } = require('./src/db'); + const start = Date.now(); + await pool.query('SELECT 1'); + diag = 'PG OK (' + (Date.now() - start) + 'ms)'; + } catch (e) { + diag = 'PG ERROR: ' + e.message; + } + res.status(503).type('html').send( + '

Сервис временно недоступен

' + + '

Таймаут запроса: 10 сек

' + + '

URL: ' + req.method + ' ' + req.url + '

' + + '

' + diag + '

' + ); } }, 10000); res.on('finish', () => clearTimeout(timer));