Fix: Bind backend to 0.0.0.0 in Docker to fix healthcheck failures and frontend proxy connection refused errors

This commit is contained in:
ypratama committed 2026-09-01 11:27:59 +07:00
1 parent 35f1838c4e
commit 450a8a5daa
1 file changed
+3 -4
+3 -4
View File
@@ -152,12 +152,11 @@ app.use((err, req, res, next) => {
});
// ─── Start Server ─────────────────────────────────────────────────────────────
// Bind to 127.0.0.1 in production to prevent direct external access to port 3001.
// All external traffic must go through the reverse proxy (Apache/Nginx) at port 80/443.
const BIND_HOST = process.env.NODE_ENV === 'production' ? '127.0.0.1' : '0.0.0.0';
// Use BIND_HOST from environment or default to 0.0.0.0 for Docker compatibility
const BIND_HOST = process.env.BIND_HOST || '0.0.0.0';
app.listen(PORT, BIND_HOST, () => {
console.log(`\n🚀 BackOne API Server berjalan di http://${BIND_HOST}:${PORT}`);
console.log(`🔌 API Health : http://${BIND_HOST}:${PORT}/api/health`);
console.log(`📡 Mode : READ-ONLY dari MongoDB (data dikirim oleh Proxy Server)`);
console.log(`🔒 Security : Bound to ${BIND_HOST} (internal only in production)\n`);
console.log(`🔒 Security : Bound to ${BIND_HOST}\n`);
});