oneuptime/Ingestor/Index.ts

60 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-05-02 14:29:22 +00:00
import 'ejs';
import { PostgresAppInstance } from 'CommonServer/Infrastructure/PostgresDatabase';
import Express, { ExpressApplication } from 'CommonServer/Utils/Express';
import logger from 'CommonServer/Utils/Logger';
2022-05-24 16:46:21 +00:00
import App from 'CommonServer/Utils/StartServer';
2023-05-02 14:29:22 +00:00
import AliveAPI from './API/Alive';
import RegisterAPI from './API/Register';
2023-05-10 17:53:36 +00:00
import MonitorAPI from './API/Monitor';
2023-10-09 17:54:23 +00:00
import Ingestor from './API/Probe';
2023-07-29 15:21:47 +00:00
import IncomingRequestAPI from './API/IncomingRequest';
2023-10-10 10:16:22 +00:00
import OTelIngestAPI from './API/OTelIngest';
2024-02-02 12:21:29 +00:00
import FluentIngestAPI from './API/FluentIngest';
2023-08-19 19:49:24 +00:00
import { ClickhouseAppInstance } from 'CommonServer/Infrastructure/ClickhouseDatabase';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';
2023-05-02 14:29:22 +00:00
import Redis from 'CommonServer/Infrastructure/Redis';
2023-11-16 18:34:23 +00:00
import Realtime from 'CommonServer/Utils/Realtime';
2023-05-02 14:29:22 +00:00
const app: ExpressApplication = Express.getExpressApp();
2022-04-20 20:14:44 +00:00
2023-10-09 17:54:23 +00:00
const APP_NAME: string = 'ingestor';
2023-05-02 14:29:22 +00:00
app.use([`/${APP_NAME}`, '/'], AliveAPI);
app.use([`/${APP_NAME}`, '/'], RegisterAPI);
2023-05-10 17:53:36 +00:00
app.use([`/${APP_NAME}`, '/'], MonitorAPI);
2023-10-09 17:54:23 +00:00
app.use([`/${APP_NAME}`, '/'], Ingestor);
2023-07-29 15:21:47 +00:00
app.use([`/${APP_NAME}`, '/'], IncomingRequestAPI);
2023-10-10 10:16:22 +00:00
app.use([`/${APP_NAME}`, '/'], OTelIngestAPI);
2024-02-02 12:21:29 +00:00
app.use([`/${APP_NAME}`, '/'], FluentIngestAPI);
2023-05-02 14:29:22 +00:00
const init: PromiseVoidFunction = async (): Promise<void> => {
2023-05-02 14:29:22 +00:00
try {
// init the app
await App(APP_NAME);
2024-02-02 12:21:29 +00:00
2023-05-02 14:29:22 +00:00
// connect to the database.
await PostgresAppInstance.connect(
PostgresAppInstance.getDatasourceOptions()
);
// connect redis
await Redis.connect();
2023-08-19 19:49:24 +00:00
2023-08-21 11:04:28 +00:00
await ClickhouseAppInstance.connect(
ClickhouseAppInstance.getDatasourceOptions()
);
2023-11-16 18:34:23 +00:00
Realtime.init();
2023-05-02 14:29:22 +00:00
} catch (err) {
logger.error('App Init Failed:');
logger.error(err);
2023-10-04 18:22:25 +00:00
throw err;
2023-05-02 14:29:22 +00:00
}
};
2023-08-10 18:00:27 +00:00
init().catch((err: Error) => {
logger.error(err);
2023-10-04 18:22:25 +00:00
logger.info('Exiting node process');
2023-09-27 19:48:50 +00:00
process.exit(1);
2023-08-10 18:00:27 +00:00
});