oneuptime/Nginx/Index.ts
2024-04-30 20:18:36 +01:00

58 lines
1.7 KiB
TypeScript

process.env['SERVICE_NAME'] = 'ingress';
import logger from 'CommonServer/Utils/Logger';
import App from 'CommonServer/Utils/StartServer';
import { PostgresAppInstance } from 'CommonServer/Infrastructure/PostgresDatabase';
import AcmeWriteCertificatesJob from './Jobs/AcmeWriteCertificates';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';
import InfrastructureStatus from 'CommonServer/Infrastructure/Status';
import FetchCertificateJobs from './Jobs/FetchCertificates';
const APP_NAME: string = process.env['SERVICE_NAME'];
const init: PromiseVoidFunction = async (): Promise<void> => {
try {
const statusCheck: PromiseVoidFunction = async (): Promise<void> => {
return await InfrastructureStatus.checkStatus({
checkClickhouseStatus: false,
checkPostgresStatus: true,
checkRedisStatus: false,
});
};
// init the app
await App.init({
appName: APP_NAME,
port: undefined,
isFrontendApp: false,
statusOptions: {
liveCheck: statusCheck,
readyCheck: statusCheck,
},
});
// connect to the database.
await PostgresAppInstance.connect(
PostgresAppInstance.getDatasourceOptions()
);
// init the jobs
FetchCertificateJobs.init();
AcmeWriteCertificatesJob.init();
// add default routes
await App.addDefaultRoutes();
} catch (err) {
logger.error('App Init Failed:');
logger.error(err);
throw err;
}
};
init().catch((err: Error) => {
logger.error(err);
logger.info('Exiting node process');
process.exit(1);
});