fixed some some mongdb stuff, and added hide objects
This commit is contained in:
parent
8edd78a341
commit
a0e1593af9
6 changed files with 37 additions and 12 deletions
3
.env
3
.env
|
|
@ -4,7 +4,8 @@
|
||||||
|
|
||||||
# Core Application Settings
|
# Core Application Settings
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
LOG_LEVEL=error
|
LOG_LEVEL=warn
|
||||||
|
LOG_HIDE_OBJECT=true
|
||||||
|
|
||||||
# Data Service Configuration
|
# Data Service Configuration
|
||||||
DATA_SERVICE_PORT=2001
|
DATA_SERVICE_PORT=2001
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Framework imports
|
// Framework imports
|
||||||
import { initializeConfig } from '@stock-bot/config';
|
import { initializeServiceConfig } from '@stock-bot/config';
|
||||||
import { Hono } from 'hono';
|
import { Hono } from 'hono';
|
||||||
import { cors } from 'hono/cors';
|
import { cors } from 'hono/cors';
|
||||||
// Library imports
|
// Library imports
|
||||||
|
|
@ -12,7 +12,7 @@ import { ProxyManager } from '@stock-bot/utils';
|
||||||
// Local imports
|
// Local imports
|
||||||
import { exchangeRoutes, healthRoutes, queueRoutes } from './routes';
|
import { exchangeRoutes, healthRoutes, queueRoutes } from './routes';
|
||||||
|
|
||||||
const config = initializeConfig();
|
const config = initializeServiceConfig();
|
||||||
console.log('Data Service Configuration:', JSON.stringify(config, null, 2));
|
console.log('Data Service Configuration:', JSON.stringify(config, null, 2));
|
||||||
const serviceConfig = config.service;
|
const serviceConfig = config.service;
|
||||||
const databaseConfig = config.database;
|
const databaseConfig = config.database;
|
||||||
|
|
@ -24,6 +24,7 @@ if (config.log) {
|
||||||
logConsole: true,
|
logConsole: true,
|
||||||
logFile: false,
|
logFile: false,
|
||||||
environment: config.environment,
|
environment: config.environment,
|
||||||
|
hideObject: config.log.hideObject,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,7 @@ export class EnvLoader implements ConfigLoader {
|
||||||
// Log mappings (using LOG_ prefix for all)
|
// Log mappings (using LOG_ prefix for all)
|
||||||
LOG_LEVEL: ['log', 'level'],
|
LOG_LEVEL: ['log', 'level'],
|
||||||
LOG_FORMAT: ['log', 'format'],
|
LOG_FORMAT: ['log', 'format'],
|
||||||
|
LOG_HIDE_OBJECT: ['log', 'hideObject'],
|
||||||
LOG_LOKI_ENABLED: ['log', 'loki', 'enabled'],
|
LOG_LOKI_ENABLED: ['log', 'loki', 'enabled'],
|
||||||
LOG_LOKI_HOST: ['log', 'loki', 'host'],
|
LOG_LOKI_HOST: ['log', 'loki', 'host'],
|
||||||
LOG_LOKI_PORT: ['log', 'loki', 'port'],
|
LOG_LOKI_PORT: ['log', 'loki', 'port'],
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
export * from './base.schema';
|
export * from './base.schema';
|
||||||
export * from './database.schema';
|
export * from './database.schema';
|
||||||
export * from './service.schema';
|
|
||||||
export * from './provider.schema';
|
export * from './provider.schema';
|
||||||
|
export * from './service.schema';
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { baseConfigSchema, environmentSchema } from './base.schema';
|
import { baseConfigSchema, environmentSchema } from './base.schema';
|
||||||
import { queueConfigSchema, httpConfigSchema } from './service.schema';
|
|
||||||
import { providerConfigSchema, webshareProviderConfigSchema } from './provider.schema';
|
import { providerConfigSchema, webshareProviderConfigSchema } from './provider.schema';
|
||||||
|
import { httpConfigSchema, queueConfigSchema } from './service.schema';
|
||||||
|
|
||||||
// Flexible service schema with defaults
|
// Flexible service schema with defaults
|
||||||
const flexibleServiceConfigSchema = z.object({
|
const flexibleServiceConfigSchema = z.object({
|
||||||
|
|
@ -74,6 +74,7 @@ const flexibleDatabaseConfigSchema = z.object({
|
||||||
const flexibleLogConfigSchema = z.object({
|
const flexibleLogConfigSchema = z.object({
|
||||||
level: z.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal']).default('info'),
|
level: z.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal']).default('info'),
|
||||||
format: z.enum(['json', 'pretty']).default('json'),
|
format: z.enum(['json', 'pretty']).default('json'),
|
||||||
|
hideObject: z.boolean().default(false),
|
||||||
loki: z.object({
|
loki: z.object({
|
||||||
enabled: z.boolean().default(false),
|
enabled: z.boolean().default(false),
|
||||||
host: z.string().default('localhost'),
|
host: z.string().default('localhost'),
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,5 @@ export interface LoggerConfig {
|
||||||
lokiUser?: string;
|
lokiUser?: string;
|
||||||
lokiPassword?: string;
|
lokiPassword?: string;
|
||||||
environment?: string;
|
environment?: string;
|
||||||
|
hideObject?: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,38 @@ import type { Db } from 'mongodb';
|
||||||
* Provides global access to a single MongoDB connection
|
* Provides global access to a single MongoDB connection
|
||||||
*/
|
*/
|
||||||
let instance: MongoDBClient | null = null;
|
let instance: MongoDBClient | null = null;
|
||||||
|
let initPromise: Promise<MongoDBClient> | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the singleton MongoDB client
|
* Initialize the singleton MongoDB client
|
||||||
*/
|
*/
|
||||||
export async function connectMongoDB(config?: MongoDBClientConfig): Promise<MongoDBClient> {
|
export async function connectMongoDB(config?: MongoDBClientConfig): Promise<MongoDBClient> {
|
||||||
if (!instance) {
|
if (instance) {
|
||||||
if (!config) {
|
return instance;
|
||||||
throw new Error('MongoDB client not initialized. Call connectMongoDB(config) first.');
|
}
|
||||||
}
|
|
||||||
instance = new MongoDBClient(config);
|
if (initPromise) {
|
||||||
await instance.connect();
|
return initPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
|
throw new Error('MongoDB client not initialized. Call connectMongoDB(config) first.');
|
||||||
|
}
|
||||||
|
|
||||||
|
initPromise = (async () => {
|
||||||
|
const client = new MongoDBClient(config);
|
||||||
|
await client.connect();
|
||||||
|
instance = client;
|
||||||
|
return client;
|
||||||
|
})();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await initPromise;
|
||||||
|
} catch (error) {
|
||||||
|
// Reset promise on error so next call can retry
|
||||||
|
initPromise = null;
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -59,4 +78,5 @@ export async function disconnectMongoDB(): Promise<void> {
|
||||||
await instance.disconnect();
|
await instance.disconnect();
|
||||||
instance = null;
|
instance = null;
|
||||||
}
|
}
|
||||||
|
initPromise = null;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue