From 809d30b53b1511114ef9ba1dc0c7519ed71c01da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Tue, 21 Jul 2026 08:31:29 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20app.listen=20outside=20initDB,=20add=20S?= =?UTF-8?q?SL=20support=20=E2=80=94=20pod=20stays=20alive=20even=20if=20PG?= =?UTF-8?q?=20down?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index b5f2bbe..97b16bb 100644 --- a/server.js +++ b/server.js @@ -22,6 +22,7 @@ const pool = new Pool({ database: process.env.PGDATABASE || "postgres", user: process.env.PGUSER || "postgres", password: process.env.PGPASSWORD || "", + ssl: process.env.PGSSLMODE === "require" ? { rejectUnauthorized: false } : false, }); const app = express(); @@ -96,8 +97,12 @@ app.post("/", async (req, res) => { }); // --- Старт --- -initDB().then(() => { - app.listen(PORT, () => { - console.log(`Node.js CRUD v${VERSION} — http://0.0.0.0:${PORT}`); - }); +// Сервер стартует всегда, даже если PG недоступен. +// initDB — асинхронно, ошибка логируется но не роняет под. +initDB() + .then(() => console.log("DB ready")) + .catch((err) => console.error("DB init failed:", err.message)); + +app.listen(PORT, () => { + console.log(`Node.js CRUD v${VERSION} — http://0.0.0.0:${PORT}`); });