Fix Coolify DB connection URL parsing for special chars in password

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-02-04 01:00:21 +01:00
parent 1a5be27a17
commit af49497923

View File

@@ -6,10 +6,19 @@ const { Pool } = pg;
let pool: pg.Pool | null = null;
function parseDbUrl(url: string): pg.PoolConfig {
// Manual parsing to handle special chars in password (/, =, etc.)
const match = url.match(/^postgres(?:ql)?:\/\/([^:]+):(.+)@([^:]+):(\d+)\/(.+)$/);
if (match) {
return { user: match[1], password: match[2], host: match[3], port: parseInt(match[4]), database: match[5] };
}
return { connectionString: url };
}
function getPool(): pg.Pool {
if (!pool) {
pool = new Pool({
connectionString: serverConfig.coolifyDbUrl,
...parseDbUrl(serverConfig.coolifyDbUrl),
max: 3,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 5000,