fix: multiple production issues with PostgreSQL and connection handling
Test and Lint / backend-test (push) Successful in 1m7s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m11s
Version and Release / version-bump (push) Successful in 36s
Version and Release / trigger-drone (push) Successful in 3s

- Fix trust proxy to use specific values instead of permissive 'true'
- Fix clear old notifications to use database-agnostic date calculation
- Fix database size check to support both PostgreSQL and SQLite
- Add caching and better error handling for session timeout queries
- Add query timeout to prevent hanging connections
- Improve JSON parsing error handling for setting values

These fixes address:
- ERR_ERL_PERMISSIVE_TRUST_PROXY warning
- PostgreSQL datetime function errors
- ENOENT errors looking for SQLite file in PostgreSQL deployment
- Connection terminated errors for session timeout checks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-07-14 12:16:56 +02:00
parent 1761ebd531
commit e8d5ee1a7b
4 changed files with 66 additions and 14 deletions
+23 -7
View File
@@ -35,14 +35,30 @@ router.get('/version', adminAuth, async (req, res) => {
// Get comprehensive system status
router.get('/status', adminAuth, async (req, res) => {
try {
// Database size
const dbPath = path.join(__dirname, '../../data/photo_sharing.db');
// Database size - check if PostgreSQL or SQLite
let dbSize = 0;
try {
const stats = await fs.stat(dbPath);
dbSize = stats.size;
} catch (error) {
console.error('Error getting database size:', error);
const dbClient = process.env.DATABASE_CLIENT || 'sqlite3';
if (dbClient === 'pg') {
// PostgreSQL - query database size
try {
const dbName = process.env.DB_NAME || 'picpeak';
const result = await db.raw(`
SELECT pg_database_size(?) as size
`, [dbName]);
dbSize = result.rows[0]?.size || 0;
} catch (error) {
console.error('Error getting PostgreSQL database size:', error);
}
} else {
// SQLite - check file size
const dbPath = path.join(__dirname, '../../data/photo_sharing.db');
try {
const stats = await fs.stat(dbPath);
dbSize = stats.size;
} catch (error) {
console.error('Error getting SQLite database size:', error);
}
}
// Count various entities