oneuptime/StatusPage/Serve.ts
Simon Larsen c3d0fe4623 fix lint.
2022-12-11 09:10:17 +00:00

42 lines
1.1 KiB
TypeScript

import App from 'CommonServer/Utils/StartServer';
import path from 'path';
import Express, {
ExpressApplication,
ExpressRequest,
ExpressResponse,
ExpressStatic,
} from 'CommonServer/Utils/Express';
import logger from 'CommonServer/Utils/Logger';
import Port from 'Common/Types/Port';
import { PostgresAppInstance } from 'CommonServer/Infrastructure/PostgresDatabase';
export const APP_NAME: string = 'status-page';
const app: ExpressApplication = Express.getExpressApp();
app.use(ExpressStatic(path.join(__dirname, 'public')));
app.use(`/${APP_NAME}`, ExpressStatic(path.join(__dirname, 'public')));
app.get('/*', (_req: ExpressRequest, res: ExpressResponse) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
const init: Function = async (): Promise<void> => {
try {
// init the app
await App(APP_NAME, new Port(3105));
// connect to the database.
await PostgresAppInstance.connect(
PostgresAppInstance.getDatasourceOptions()
);
} catch (err) {
logger.error('App Init Failed:');
logger.error(err);
}
};
init();
export default app;