cordis/server/app.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-10-30 17:26:41 +00:00
import * as https from 'http';
import * as fs from 'fs';
import * as path from 'path';
import * as socketio from 'socket.io';
import { ExitCodes, ExitCode } from '../exit-codes/exit-codes';
import Logger from '../logger/logger';
import * as controller from './server-controller';
import DB from './db';
const LOG = new Logger('app');
//@ts-ignore The https bindings are wrong...
const server = https.createServer({ key: fs.readFileSync(path.join(__dirname, 'ssl/key.pem')), cert: fs.readFileSync(path.join(__dirname, 'ssl/cert.pem')), });
process.on('unhandledRejection', (reason: any, _promise: Promise<unknown>) => {
LOG.error('unhandled promise rejection:', reason);
ExitCodes.exit(ExitCode.GENERAL_ERROR);
});
// Why js doesn't just do this by default, IDK
(async () => {
await DB.connect();
let servers = await DB.getAllServers();
for (let server of servers) {
LOG.debug(`s#${server.id}: ${server.name}`);
await DB.clearAllMemberStatus(server.id);
}
const io = new socketio.Server(server, {
maxHttpBufferSize: 1024 * 1024 * 51, // 51 MB to allow for 1MB past the max resource size
});
controller.bindSocketEvents(io);
server.listen(3030);
LOG.info('listening on port 3030');
})();