import * as https from 'https'; import * as path from 'path'; import * as fs from 'fs'; 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 = Logger.create('app'); const server = https.createServer({ cert: fs.readFileSync(path.join(__dirname, 'ssl/cert.pem')).toString(), key: fs.readFileSync(path.join(__dirname, 'ssl/key.pem')).toString() }); 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'); })();