0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00
logto/packages/core/src/index.ts

32 lines
872 B
TypeScript
Raw Normal View History

import { noop } from '@silverhand/essentials';
2023-01-07 17:22:15 +08:00
import dotenv from 'dotenv';
import { findUp } from 'find-up';
2021-08-30 11:30:54 +08:00
import Koa from 'koa';
2021-07-11 17:59:44 +08:00
2022-11-21 16:38:24 +08:00
import initI18n from './i18n/init.js';
2021-06-06 18:30:37 +08:00
2023-01-07 17:22:15 +08:00
dotenv.config({ path: await findUp('.env', {}) });
// Import after env has configured
const { default: envSet } = await import('./env-set/index.js');
await envSet.load();
const { loadConnectorFactories } = await import('./connectors/index.js');
try {
const app = new Koa({
proxy: envSet.values.trustProxyHeader,
});
await initI18n();
2023-01-03 15:41:29 +08:00
await loadConnectorFactories();
2022-12-22 13:50:49 +08:00
// Import last until init completed
const { default: initApp } = await import('./app/init.js');
await initApp(app);
} catch (error: unknown) {
console.error('Error while initializing app:');
console.error(error);
await Promise.all([envSet.poolSafe?.end(), envSet.queryClientSafe?.end()]).catch(noop);
}