fix: clean up service configuration startup and development commands

This commit is contained in:
Boki 2026-10-26 13:23:49 -04:00
parent 4ddffa6b67
commit 805a9f8fd4
36 changed files with 627 additions and 596 deletions

View file

@ -14,18 +14,21 @@ export function registerDatabaseServices(
if (config.mongodb?.enabled) {
container.register({
mongoClient: asFunction(({ logger }) => {
// Parse MongoDB URI to extract components
const uriMatch = config.mongodb.uri.match(
/mongodb:\/\/(?:([^:]+):([^@]+)@)?([^:/]+):(\d+)\/([^?]+)(?:\?authSource=(.+))?/
);
// The driver parses URI credentials, SRV and query options. Do not
// reconstruct them with an incomplete URI regular expression.
const mongoConfig = {
host: uriMatch?.[3] || 'localhost',
port: parseInt(uriMatch?.[4] || '27017'),
host: config.mongodb.host ?? 'localhost',
port: config.mongodb.port ?? 27017,
database: config.mongodb.database,
username: uriMatch?.[1],
password: uriMatch?.[2] ? String(uriMatch?.[2]) : undefined,
authSource: uriMatch?.[6] || 'admin',
username: config.mongodb.user,
password: config.mongodb.password,
authSource: config.mongodb.authSource,
uri: config.mongodb.uri,
poolSettings: {
maxPoolSize: config.mongodb.poolSize,
minPoolSize: 0,
maxIdleTime: 10000,
},
};
return new MongoDBClient(mongoConfig, logger);
}).singleton(),
@ -45,7 +48,20 @@ export function registerDatabaseServices(
port: config.postgres.port,
database: config.postgres.database,
username: config.postgres.user,
password: String(config.postgres.password), // Ensure password is a string
password: config.postgres.password,
ssl: { enabled: config.postgres.ssl, rejectUnauthorized: true },
poolSettings: {
min: 0,
max: config.postgres.poolSize,
idleTimeoutMillis: config.postgres.idleTimeout,
},
timeouts: {
connection: config.postgres.connectionTimeout,
query: 0,
statement: 0,
lock: 0,
idleInTransaction: 0,
},
};
logger.debug('PostgreSQL config:', {