oneuptime/ProbeAPI/Index.ts

50 lines
1.5 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-05-11 15:29:38 +00:00
import ProbeAPI from './API/Probe';
2023-07-29 15:21:47 +00:00
import IncomingRequestAPI from './API/IncomingRequest';
2023-08-19 19:49:24 +00:00
import { ClickhouseAppInstance } from 'CommonServer/Infrastructure/ClickhouseDatabase';
2022-05-24 16:46:21 +00:00
2023-05-02 14:29:22 +00:00
import Redis from 'CommonServer/Infrastructure/Redis';
2023-05-02 14:29:22 +00:00
const app: ExpressApplication = Express.getExpressApp();
2022-04-20 20:14:44 +00:00
2023-05-02 14:29:22 +00:00
const APP_NAME: string = 'probe-api';
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-05-11 15:29:38 +00:00
app.use([`/${APP_NAME}`, '/'], ProbeAPI);
2023-07-29 15:21:47 +00:00
app.use([`/${APP_NAME}`, '/'], IncomingRequestAPI);
2023-05-02 14:29:22 +00:00
2023-08-10 17:25:15 +00:00
const init: () => Promise<void> = async (): Promise<void> => {
2023-05-02 14:29:22 +00:00
try {
// init the app
await App(APP_NAME);
// 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-05-02 14:29:22 +00:00
} catch (err) {
logger.error('App Init Failed:');
logger.error(err);
}
};
2023-08-10 18:00:27 +00:00
init().catch((err: Error) => {
logger.error(err);
2023-09-27 19:48:50 +00:00
process.exit(1);
2023-08-10 18:00:27 +00:00
});