cordis/server/app.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

import * as https from 'https';
2021-10-30 17:26:41 +00:00
import * as path from 'path';
import * as fs from 'fs';
2021-10-30 17:26:41 +00:00
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';
2021-11-02 04:29:24 +00:00
const LOG = Logger.create('app');
2021-10-30 17:26:41 +00:00
const server = https.createServer({
cert: fs.readFileSync(path.join(__dirname, 'ssl/cert.pem')).toString(),
key: fs.readFileSync(path.join(__dirname, 'ssl/key.pem')).toString()
});
2021-10-30 17:26:41 +00:00
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);
2021-10-30 17:26:41 +00:00
}
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');
})();