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) => { 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'); })();