2024-06-14 11:09:53 +00:00
|
|
|
import APIReferenceRoutes from "./FeatureSet/ApiReference/Index";
|
|
|
|
import BaseAPIRoutes from "./FeatureSet/BaseAPI/Index";
|
|
|
|
import DocsRoutes from "./FeatureSet/Docs/Index";
|
|
|
|
import HomeRoutes from "./FeatureSet/Home/Index";
|
2024-04-24 11:20:04 +00:00
|
|
|
// import FeatureSets.
|
2024-06-14 11:09:53 +00:00
|
|
|
import IdentityRoutes from "./FeatureSet/Identity/Index";
|
|
|
|
import NotificationRoutes from "./FeatureSet/Notification/Index";
|
|
|
|
import Workers from "./FeatureSet/Workers/Index";
|
|
|
|
import Workflow from "./FeatureSet/Workflow/Index";
|
|
|
|
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
|
2024-08-07 21:50:32 +00:00
|
|
|
import { ClickhouseAppInstance } from "Common/Server/Infrastructure/ClickhouseDatabase";
|
2024-08-20 16:37:45 +00:00
|
|
|
import PostgresAppInstance from "Common/Server/Infrastructure/PostgresDatabase";
|
2024-08-07 21:50:32 +00:00
|
|
|
import Redis from "Common/Server/Infrastructure/Redis";
|
|
|
|
import InfrastructureStatus from "Common/Server/Infrastructure/Status";
|
|
|
|
import logger from "Common/Server/Utils/Logger";
|
|
|
|
import Realtime from "Common/Server/Utils/Realtime";
|
|
|
|
import App from "Common/Server/Utils/StartServer";
|
|
|
|
import Telemetry from "Common/Server/Utils/Telemetry";
|
2024-06-14 11:09:53 +00:00
|
|
|
import "ejs";
|
2022-07-07 19:42:19 +00:00
|
|
|
|
2024-08-02 22:35:09 +00:00
|
|
|
const APP_NAME: string = "app";
|
2023-12-28 19:57:21 +00:00
|
|
|
|
2024-02-27 15:37:49 +00:00
|
|
|
const init: PromiseVoidFunction = async (): Promise<void> => {
|
2024-06-14 11:09:53 +00:00
|
|
|
try {
|
2024-08-02 22:35:09 +00:00
|
|
|
// Initialize telemetry
|
|
|
|
Telemetry.init({
|
|
|
|
serviceName: APP_NAME,
|
|
|
|
});
|
2024-08-02 22:50:13 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const statusCheck: PromiseVoidFunction = async (): Promise<void> => {
|
2024-07-14 21:37:48 +00:00
|
|
|
// Check the status of infrastructure components
|
2024-06-14 11:09:53 +00:00
|
|
|
return await InfrastructureStatus.checkStatus({
|
|
|
|
checkClickhouseStatus: true,
|
|
|
|
checkPostgresStatus: true,
|
|
|
|
checkRedisStatus: true,
|
|
|
|
});
|
|
|
|
};
|
2024-04-24 13:02:17 +00:00
|
|
|
|
2024-07-14 21:37:48 +00:00
|
|
|
// Initialize the app with service name and status checks
|
2024-06-14 11:09:53 +00:00
|
|
|
await App.init({
|
2024-08-02 22:35:09 +00:00
|
|
|
appName: APP_NAME,
|
2024-06-14 11:09:53 +00:00
|
|
|
statusOptions: {
|
|
|
|
liveCheck: statusCheck,
|
|
|
|
readyCheck: statusCheck,
|
|
|
|
},
|
|
|
|
});
|
2023-10-27 15:17:28 +00:00
|
|
|
|
2024-07-14 21:37:48 +00:00
|
|
|
// Connect to Postgres database
|
2024-08-13 13:37:23 +00:00
|
|
|
await PostgresAppInstance.connect();
|
2022-07-14 13:34:48 +00:00
|
|
|
|
2024-07-14 21:37:48 +00:00
|
|
|
// Connect to Redis
|
2024-06-14 11:09:53 +00:00
|
|
|
await Redis.connect();
|
2023-08-19 19:49:24 +00:00
|
|
|
|
2024-07-14 21:37:48 +00:00
|
|
|
// Connect to Clickhouse database
|
2024-06-14 11:09:53 +00:00
|
|
|
await ClickhouseAppInstance.connect(
|
|
|
|
ClickhouseAppInstance.getDatasourceOptions(),
|
|
|
|
);
|
2023-11-16 17:16:37 +00:00
|
|
|
|
2024-07-14 21:37:48 +00:00
|
|
|
// Initialize real-time functionalities
|
2024-06-14 11:09:53 +00:00
|
|
|
await Realtime.init();
|
2024-01-11 10:55:58 +00:00
|
|
|
|
2024-07-14 21:37:48 +00:00
|
|
|
// Initialize feature sets
|
2024-06-14 11:09:53 +00:00
|
|
|
await IdentityRoutes.init();
|
|
|
|
await NotificationRoutes.init();
|
|
|
|
await DocsRoutes.init();
|
|
|
|
await BaseAPIRoutes.init();
|
|
|
|
await APIReferenceRoutes.init();
|
|
|
|
await Workers.init();
|
|
|
|
await Workflow.init();
|
2024-04-24 11:20:04 +00:00
|
|
|
|
2024-07-14 21:37:48 +00:00
|
|
|
// Initialize home routes at the end since it has a catch-all route
|
2024-06-14 11:09:53 +00:00
|
|
|
await HomeRoutes.init();
|
2024-04-24 11:20:04 +00:00
|
|
|
|
2024-07-14 21:37:48 +00:00
|
|
|
// Add default routes to the app
|
2024-06-14 11:09:53 +00:00
|
|
|
await App.addDefaultRoutes();
|
|
|
|
} catch (err) {
|
|
|
|
logger.error("App Init Failed:");
|
|
|
|
logger.error(err);
|
|
|
|
throw err;
|
|
|
|
}
|
2022-07-07 19:42:19 +00:00
|
|
|
};
|
2021-04-01 08:26:13 +00:00
|
|
|
|
2023-08-10 18:00:27 +00:00
|
|
|
init().catch((err: Error) => {
|
2024-06-14 11:09:53 +00:00
|
|
|
logger.error(err);
|
|
|
|
logger.error("Exiting node process");
|
|
|
|
process.exit(1);
|
2023-08-10 18:00:27 +00:00
|
|
|
});
|