2022-01-22 19:51:29 +00:00
|
|
|
import { config } from 'dotenv';
|
2022-01-22 21:37:59 +00:00
|
|
|
import Express from "express";
|
2022-01-22 19:51:29 +00:00
|
|
|
import Log75, { LogLevel } from 'log75';
|
2022-01-23 13:54:40 +00:00
|
|
|
import buildDBClient from './db';
|
2022-01-22 19:51:29 +00:00
|
|
|
|
|
|
|
config();
|
|
|
|
|
|
|
|
const PORT = Number(process.env.API_PORT || 9000);
|
|
|
|
const DEBUG = process.env.NODE_ENV != 'production';
|
2022-01-23 13:54:40 +00:00
|
|
|
const SESSION_LIFETIME = 1000 * 60 * 60 * 24 * 7;
|
2022-01-22 19:51:29 +00:00
|
|
|
|
|
|
|
const logger: Log75 = new (Log75 as any).default(DEBUG ? LogLevel.Debug : LogLevel.Standard);
|
2022-01-23 13:54:40 +00:00
|
|
|
const db = buildDBClient();
|
2022-01-22 19:51:29 +00:00
|
|
|
const app = Express();
|
|
|
|
|
2022-02-05 21:46:50 +00:00
|
|
|
app.set('trust proxy', true);
|
2022-01-23 13:54:40 +00:00
|
|
|
app.use(Express.json());
|
|
|
|
|
|
|
|
export { logger, app, db, PORT, SESSION_LIFETIME }
|
2022-01-22 19:51:29 +00:00
|
|
|
|
2022-01-22 21:37:59 +00:00
|
|
|
(async () => {
|
2022-02-05 14:59:45 +00:00
|
|
|
const promises = [
|
2022-01-22 21:37:59 +00:00
|
|
|
import('./middlewares/log'),
|
2022-01-23 13:54:40 +00:00
|
|
|
import('./middlewares/updateTokenExpiry'),
|
2022-01-23 22:23:09 +00:00
|
|
|
import('./middlewares/cors'),
|
2022-02-05 21:46:50 +00:00
|
|
|
import('./middlewares/ratelimit'),
|
|
|
|
|
2022-01-22 21:37:59 +00:00
|
|
|
import('./routes/internal/ws'),
|
|
|
|
import('./routes/root'),
|
2022-03-23 19:13:43 +00:00
|
|
|
import('./routes/stats'),
|
2022-01-23 13:54:40 +00:00
|
|
|
import('./routes/login'),
|
2022-01-24 18:01:18 +00:00
|
|
|
import('./routes/dash/servers'),
|
2022-01-25 07:36:48 +00:00
|
|
|
import('./routes/dash/server'),
|
2022-02-05 14:59:45 +00:00
|
|
|
import('./routes/dash/server-automod'),
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const p of promises) await p;
|
|
|
|
|
|
|
|
|
2022-01-22 21:37:59 +00:00
|
|
|
logger.done('All routes and middlewares loaded');
|
|
|
|
})();
|
|
|
|
|
|
|
|
import('./server');
|