Fix: таймаут 10с на все запросы — не висим, не даём nginx 503. Версия 0.1.25

This commit is contained in:
“Naeel”
2026-07-09 10:36:17 +04:00
parent 944faf8277
commit d62f646e17
2 changed files with 12 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "ipwhitelist",
"version": "0.1.24",
"version": "0.1.25",
"description": "IP WhiteList microservice for cloud provider",
"main": "server.js",
"scripts": {
+11
View File
@@ -57,6 +57,17 @@ app.use(cookieParser());
async function start() {
const auth = await initAuth();
// ── Стоп-кран: если запрос висит > 10 сек — обрываем с ошибкой ───────
app.use((req, res, next) => {
const timer = setTimeout(() => {
if (!res.headersSent) {
res.status(503).type('html').send('<h2>Сервис временно недоступен</h2><p>Превышено время ожидания</p>');
}
}, 10000);
res.on('finish', () => clearTimeout(timer));
next();
});
// ── Сессии ────────────────────────────────────────────────────────────────
const { pool } = require('./src/db');
app.use(createSessionMiddleware(pool));