2021-09-23 00:52:35 +02:00
|
|
|
import { config } from "./config";
|
|
|
|
import { initDb } from "./databases/databases";
|
|
|
|
import { createServer } from "./app";
|
|
|
|
import { Logger } from "./utils/logger";
|
|
|
|
import { startAllCrons } from "./cronjob";
|
2021-09-01 22:52:41 +02:00
|
|
|
import { getCommit } from "./utils/getCommit";
|
2022-11-20 07:20:05 +01:00
|
|
|
import { connectionPromise } from "./utils/redis";
|
2020-10-20 21:56:07 +02:00
|
|
|
|
2021-03-07 06:21:56 +01:00
|
|
|
async function init() {
|
2021-09-28 15:48:24 +02:00
|
|
|
process.on("unhandledRejection", (error: any) => {
|
2021-10-27 02:37:49 +02:00
|
|
|
// eslint-disable-next-line no-console
|
2021-09-28 15:56:32 +02:00
|
|
|
console.dir(error?.stack);
|
2021-09-29 18:22:40 +02:00
|
|
|
process.exit(1);
|
2021-09-28 15:48:24 +02:00
|
|
|
});
|
|
|
|
|
2022-10-27 07:30:59 +02:00
|
|
|
try {
|
|
|
|
await initDb();
|
2022-11-20 07:20:05 +01:00
|
|
|
await connectionPromise;
|
2022-10-27 07:30:59 +02:00
|
|
|
} catch (e) {
|
|
|
|
Logger.error(`Init Db: ${e}`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2021-10-22 17:37:32 +02:00
|
|
|
// edge case clause for creating compatible .db files, do not enable
|
|
|
|
if (config.mode === "init-db-and-exit") process.exit(0);
|
|
|
|
// do not enable init-db-only mode for usage.
|
2021-09-01 22:52:41 +02:00
|
|
|
(global as any).HEADCOMMIT = config.mode === "development" ? "development"
|
|
|
|
: config.mode === "test" ? "test"
|
|
|
|
: getCommit() as string;
|
2021-03-07 06:21:56 +01:00
|
|
|
createServer(() => {
|
2021-07-12 08:12:22 +02:00
|
|
|
Logger.info(`Server started on port ${config.port}.`);
|
2021-07-09 06:46:04 +02:00
|
|
|
|
|
|
|
// ignite cron job after server created
|
|
|
|
startAllCrons();
|
2022-02-19 22:02:05 +01:00
|
|
|
}).setTimeout(15000);
|
2021-03-07 06:21:56 +01:00
|
|
|
}
|
2021-07-09 06:46:04 +02:00
|
|
|
|
2022-10-27 07:30:59 +02:00
|
|
|
init().catch((err) => Logger.error(`Index.js: ${err}`));
|