import RedisOptions,{ Redis, ICache } from "@arborknot/cache"; import { PredefinedConfig, RuntimeConfig } from "@config"; import { Webhooks } from "@domain-objects"; import { Server } from "@server"; import { WebhookController } from "@server/controllers/webhook.controller"; import { WebhookRouter } from "@server/routes/webhook.route"; import { PoolConfig } from "pg"; import { PgPool } from '@arborknot/db' import { loggerManager } from "@logger"; async function main() { const predefinedConfig = new PredefinedConfig(); // export interface RedisOptinons { // port: number; // host: string; // username?: string; // password?: string; // [key: string]: any; //} const cacheConfig = { sentinels: [{ host: predefinedConfig.CACHE_HOST, port: predefinedConfig.CACHE_PORT }], sentinelPassword: predefinedConfig.CACHE_PASSWORD, port:6379, host:"localhost", password: predefinedConfig.CACHE_PASSWORD, name: "mymaster", commandTimeout: predefinedConfig.CACHE_COMMAND_TIMEOUT_MILLIS, connectTimeout: predefinedConfig.CACHE_CONNECTION_TIMEOUT_MILLIS, lazyConnect: true, }; const cache= new Redis(cacheConfig); const config = new PredefinedConfig(); const poolConfig: PoolConfig = { host: config.DB_HOST, database: config.DB_NAME, port: config.DB_PORT, user: config.DB_USERNAME, password: config.DB_PASSWORD, // min: config.DB_MIN_CONNECTIONS_ALLOWED, // max: config.DB_MAX_CONNECTIONS_ALLOWED, // idle_in_transaction_session_timeout: config.DB_IDLE_IN_TRANSACTION_SESSION_TIMEOUT_MILLIS, // connectionTimeoutMillis: config.DB_CONNECTION_TIMEOUT_MILLIS, }; const db = new PgPool(poolConfig, loggerManager); await db.connect(); const runtimeConfig = new RuntimeConfig(db); await runtimeConfig.setServiceEnvironmentVariablesFromDB(); await runtimeConfig.listenToServiceEnvironmentVariableChangeOnDB(); //loggerManager.assignRuntimeConfig(runtimeConfig); const webhooks = new Webhooks(db, cache); const server = new Server(new WebhookRouter(new WebhookController(webhooks)), predefinedConfig); await server.start(); } main();