From 4397ca29edc87d6c46e2734ef3d88a7ad3b6be9f Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Mon, 6 May 2024 17:12:36 +0800 Subject: [PATCH] refactor(core): optimize init (#5826) --- packages/core/src/main.ts | 5 ++--- packages/core/src/tenants/index.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/src/main.ts b/packages/core/src/main.ts index 3144800d6..3ead694a2 100644 --- a/packages/core/src/main.ts +++ b/packages/core/src/main.ts @@ -1,8 +1,10 @@ +import { appInsights } from '@logto/app-insights/node'; import { ConsoleLog } from '@logto/shared'; import { trySafe } from '@silverhand/essentials'; import chalk from 'chalk'; import Koa from 'koa'; +import initApp from './app/init.js'; import { redisCache } from './caches/index.js'; import { checkAlterationState } from './env-set/check-alteration-state.js'; import { EnvSet } from './env-set/index.js'; @@ -11,7 +13,6 @@ import SystemContext from './tenants/SystemContext.js'; import { checkRowLevelSecurity, tenantPool } from './tenants/index.js'; import { loadConnectorFactories } from './utils/connectors/index.js'; -const { appInsights } = await import('@logto/app-insights/node'); const consoleLog = new ConsoleLog(chalk.magenta('index')); if (await appInsights.setup('core')) { @@ -33,8 +34,6 @@ try { SystemContext.shared.loadProviderConfigs(sharedAdminPool), ]); - // Import last until init completed - const { default: initApp } = await import('./app/init.js'); await initApp(app); } catch (error: unknown) { consoleLog.error('Error while initializing app:'); diff --git a/packages/core/src/tenants/index.ts b/packages/core/src/tenants/index.ts index cb39c2b44..5e43ee85b 100644 --- a/packages/core/src/tenants/index.ts +++ b/packages/core/src/tenants/index.ts @@ -31,7 +31,7 @@ class TenantPool { // Otherwise, create a new tenant instance and store in LRU cache, using the code below. } - consoleLog.info('Init tenant:', tenantId, customDomain); + consoleLog.info('Init tenant:', tenantId, 'Custom domain:', customDomain); const newTenantPromise = Tenant.create({ id: tenantId, redisCache, customDomain }); this.cache.set(cacheKey, newTenantPromise);