fixed web-api
This commit is contained in:
parent
46de1755e9
commit
96f515a76b
3 changed files with 71 additions and 13 deletions
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
import { Hono } from 'hono';
|
||||
import { cors } from 'hono/cors';
|
||||
import { initializeConfig, getServiceConfig, getLoggingConfig } from '@stock-bot/config-new';
|
||||
import { initializeConfig, getServiceConfig, getLoggingConfig, getDatabaseConfig } from '@stock-bot/config-new';
|
||||
import { getLogger, shutdownLoggers, setLoggerConfig } from '@stock-bot/logger';
|
||||
import { createAndConnectMongoDBClient, MongoDBClient } from '@stock-bot/mongodb-client';
|
||||
import { createAndConnectPostgreSQLClient, PostgreSQLClient } from '@stock-bot/postgres-client';
|
||||
|
|
@ -16,6 +16,7 @@ import { healthRoutes } from './routes/health.routes';
|
|||
// Initialize configuration
|
||||
await initializeConfig();
|
||||
const serviceConfig = getServiceConfig();
|
||||
const databaseConfig = getDatabaseConfig();
|
||||
|
||||
// Initialize logger with config
|
||||
const loggingConfig = getLoggingConfig();
|
||||
|
|
@ -75,16 +76,16 @@ async function initializeServices() {
|
|||
try {
|
||||
// Initialize MongoDB client
|
||||
logger.info('Connecting to MongoDB...');
|
||||
const mongoConfig = serviceConfig.database.mongodb;
|
||||
const mongoConfig = databaseConfig.mongodb;
|
||||
mongoClient = await createAndConnectMongoDBClient({
|
||||
uri: mongoConfig.uri,
|
||||
database: mongoConfig.database,
|
||||
host: 'localhost',
|
||||
port: 27017,
|
||||
host: mongoConfig.host,
|
||||
port: mongoConfig.port,
|
||||
timeouts: {
|
||||
connectTimeout: mongoConfig.connectionTimeout || 30000,
|
||||
connectTimeout: 30000,
|
||||
socketTimeout: 30000,
|
||||
serverSelectionTimeout: mongoConfig.serverSelectionTimeout || 5000,
|
||||
serverSelectionTimeout: 5000,
|
||||
},
|
||||
});
|
||||
setMongoDBClient(mongoClient);
|
||||
|
|
@ -92,17 +93,17 @@ async function initializeServices() {
|
|||
|
||||
// Initialize PostgreSQL client
|
||||
logger.info('Connecting to PostgreSQL...');
|
||||
const pgConfig = serviceConfig.database.postgres;
|
||||
const pgConfig = databaseConfig.postgres;
|
||||
postgresClient = await createAndConnectPostgreSQLClient({
|
||||
host: pgConfig.host,
|
||||
port: pgConfig.port,
|
||||
database: pgConfig.database,
|
||||
username: pgConfig.username,
|
||||
username: pgConfig.user,
|
||||
password: pgConfig.password,
|
||||
poolSettings: {
|
||||
min: 2,
|
||||
max: pgConfig.maxConnections || 10,
|
||||
idleTimeoutMillis: 30000,
|
||||
max: pgConfig.poolSize || 10,
|
||||
idleTimeoutMillis: pgConfig.idleTimeout || 30000,
|
||||
},
|
||||
});
|
||||
setPostgreSQLClient(postgresClient);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,13 @@ import {
|
|||
const logger = getLogger('exchange-service');
|
||||
|
||||
export class ExchangeService {
|
||||
private postgresClient = getPostgreSQLClient();
|
||||
private mongoClient = getMongoDBClient();
|
||||
private get postgresClient() {
|
||||
return getPostgreSQLClient();
|
||||
}
|
||||
|
||||
private get mongoClient() {
|
||||
return getMongoDBClient();
|
||||
}
|
||||
|
||||
// Exchanges
|
||||
async getAllExchanges(): Promise<ExchangeWithMappings[]> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue