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:
@@ -6,10 +6,19 @@ const { Pool } = pg;
|
|||||||
|
|
||||||
let pool: pg.Pool | null = null;
|
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 {
|
function getPool(): pg.Pool {
|
||||||
if (!pool) {
|
if (!pool) {
|
||||||
pool = new Pool({
|
pool = new Pool({
|
||||||
connectionString: serverConfig.coolifyDbUrl,
|
...parseDbUrl(serverConfig.coolifyDbUrl),
|
||||||
max: 3,
|
max: 3,
|
||||||
idleTimeoutMillis: 30000,
|
idleTimeoutMillis: 30000,
|
||||||
connectionTimeoutMillis: 5000,
|
connectionTimeoutMillis: 5000,
|
||||||
|
|||||||
Reference in New Issue
Block a user