AutoMod/api/src/index.ts

44 lines
1.1 KiB
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-02-05 22:46:50 +01:00
app.set('trust proxy', true);
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 () => {
const promises = [
2022-01-22 22:37:59 +01:00
import('./middlewares/log'),
2022-01-23 14:54:40 +01:00
import('./middlewares/updateTokenExpiry'),
2022-01-23 23:23:09 +01:00
import('./middlewares/cors'),
2022-02-05 22:46:50 +01:00
import('./middlewares/ratelimit'),
2022-01-22 22:37:59 +01:00
import('./routes/internal/ws'),
import('./routes/root'),
2022-03-23 20:13:43 +01:00
import('./routes/stats'),
2022-01-23 14:54:40 +01:00
import('./routes/login'),
2022-01-24 19:01:18 +01:00
import('./routes/dash/servers'),
2022-01-25 08:36:48 +01:00
import('./routes/dash/server'),
import('./routes/dash/server-automod'),
];
for (const p of promises) await p;
2022-01-22 22:37:59 +01:00
logger.done('All routes and middlewares loaded');
})();
import('./server');