AutoMod/api/src/index.ts

32 lines
852 B
TypeScript
Raw Normal View History

2022-01-22 20:51:29 +01:00
import { config } from 'dotenv';
2022-01-22 22:37:59 +01:00
import Express from "express";
2022-01-22 20:51:29 +01:00
import Log75, { LogLevel } from 'log75';
2022-01-23 14:54:40 +01:00
import buildDBClient from './db';
2022-01-22 20:51:29 +01:00
config();
const PORT = Number(process.env.API_PORT || 9000);
const DEBUG = process.env.NODE_ENV != 'production';
2022-01-23 14:54:40 +01:00
const SESSION_LIFETIME = 1000 * 60 * 60 * 24 * 7;
2022-01-22 20:51:29 +01:00
const logger: Log75 = new (Log75 as any).default(DEBUG ? LogLevel.Debug : LogLevel.Standard);
2022-01-23 14:54:40 +01:00
const db = buildDBClient();
2022-01-22 20:51:29 +01:00
const app = Express();
2022-01-23 14:54:40 +01:00
app.use(Express.json());
export { logger, app, db, PORT, SESSION_LIFETIME }
2022-01-22 20:51:29 +01:00
2022-01-22 22:37:59 +01:00
(async () => {
await Promise.all([
import('./middlewares/log'),
2022-01-23 14:54:40 +01:00
import('./middlewares/updateTokenExpiry'),
2022-01-22 22:37:59 +01:00
import('./routes/internal/ws'),
import('./routes/root'),
2022-01-23 14:54:40 +01:00
import('./routes/login'),
2022-01-22 22:37:59 +01:00
]);
logger.done('All routes and middlewares loaded');
})();
import('./server');