44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
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<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 guilds = await DB.getAllGuilds();
|
|
for (let guild of guilds) {
|
|
LOG.debug(`g#${guild.id}: ${guild.name}`);
|
|
await DB.clearAllMemberStatus(guild.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');
|
|
})();
|