From 52dd557e24325b7f2ca912bacfde4cb087ed7852 Mon Sep 17 00:00:00 2001 From: amina69 Date: Mon, 29 Jun 2026 21:13:13 +0100 Subject: [PATCH 1/3] fix --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e12effc..da87a57 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # SwiftChain_Backend +setup linked: 1 **SwiftChain_Backend** is the core API service for **SwiftChain**, a Blockchain-Powered Logistics & Escrow Delivery Platform. It connects individuals, businesses, and independent drivers in a decentralized logistics economy, ensuring trust through escrow payments and smart contracts. From ce731dd82899dcf16e48688722325805c2c6c596 Mon Sep 17 00:00:00 2001 From: amina69 Date: Mon, 29 Jun 2026 21:14:38 +0100 Subject: [PATCH 2/3] fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da87a57..b187bf3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # SwiftChain_Backend -setup linked: 1 +setup linked: 1,3 **SwiftChain_Backend** is the core API service for **SwiftChain**, a Blockchain-Powered Logistics & Escrow Delivery Platform. It connects individuals, businesses, and independent drivers in a decentralized logistics economy, ensuring trust through escrow payments and smart contracts. From 6323accecb1322fa023fb5f733d132f7a109f134 Mon Sep 17 00:00:00 2001 From: amina69 Date: Wed, 1 Jul 2026 09:53:15 +0100 Subject: [PATCH 3/3] done --- README.md | 1 - package.json | 9 ++++++++- src/config/database.ts | 21 ++++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b187bf3..e12effc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # SwiftChain_Backend -setup linked: 1,3 **SwiftChain_Backend** is the core API service for **SwiftChain**, a Blockchain-Powered Logistics & Escrow Delivery Platform. It connects individuals, businesses, and independent drivers in a decentralized logistics economy, ensuring trust through escrow payments and smart contracts. diff --git a/package.json b/package.json index eeeb8c4..7245e2f 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "start": "node dist/server.js", "lint": "eslint . --ext .ts", "format": "prettier --write .", - "test": "jest" + "test": "jest", + "prepare": "husky install" }, "dependencies": { "bcryptjs": "2.4.3", @@ -53,5 +54,11 @@ "ts-jest": "^29.4.11", "ts-node": "10.9.2", "typescript": "5.2.2" + }, + "lint-staged": { + "*.ts": [ + "eslint --fix", + "prettier --write" + ] } } diff --git a/src/config/database.ts b/src/config/database.ts index 65bb270..8283b38 100644 --- a/src/config/database.ts +++ b/src/config/database.ts @@ -5,7 +5,12 @@ export const connectDatabase = async (): Promise => { try { const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/swiftchain'; - await mongoose.connect(mongoUri); + await mongoose.connect(mongoUri, { + maxPoolSize: 10, // Maximum number of connections in the pool + minPoolSize: 2, // Minimum number of connections in the pool + serverSelectionTimeoutMS: 5000, // Timeout after 5s instead of 30s + socketTimeoutMS: 45000, // Close sockets after 45s of inactivity + }); logger.info('✅ Connected to MongoDB successfully'); @@ -16,6 +21,20 @@ export const connectDatabase = async (): Promise => { mongoose.connection.on('disconnected', () => { logger.warn('MongoDB disconnected'); }); + + mongoose.connection.on('reconnected', () => { + logger.info('✅ MongoDB reconnected'); + }); + + mongoose.connection.on('connected', () => { + logger.info(`MongoDB connected to ${mongoose.connection.host}`); + }); + + process.on('SIGINT', async () => { + await mongoose.connection.close(); + logger.info('MongoDB connection closed through app termination'); + process.exit(0); + }); } catch (error) { logger.error('❌ Failed to connect to MongoDB:', error); process.exit(1);