2022-12-23 19:09:09 +08:00
|
|
|
import { noop } from '@silverhand/essentials';
|
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 { configDotEnv } from './env-set/dot-env.js';
|
|
|
|
import envSet from './env-set/index.js';
|
|
|
|
import initI18n from './i18n/init.js';
|
2021-06-06 18:30:37 +08:00
|
|
|
|
2022-12-23 19:09:09 +08:00
|
|
|
try {
|
|
|
|
await configDotEnv();
|
|
|
|
await envSet.load();
|
|
|
|
const app = new Koa({
|
|
|
|
proxy: envSet.values.trustProxyHeader,
|
|
|
|
});
|
|
|
|
await initI18n();
|
2022-12-22 13:50:49 +08:00
|
|
|
|
2022-12-23 19:09:09 +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);
|
|
|
|
}
|