Compare commits

..

2 Commits

View File

@ -9,6 +9,7 @@ import express, { Express, NextFunction } from 'express';
import helmet from 'helmet';
import cors from 'cors';
import MongoStore from 'connect-mongo';
import { Collection } from '@discordjs/collection';
// Own
import { LogFunction, LoggerClient } from '@navy.gif/logger';
@ -25,7 +26,6 @@ import { MongoMemory } from './database/index.js';
import { IPCMessage, SignupCode } from '../../@types/Other.js';
import { DoneCallback } from 'passport';
import FlagManager from './components/FlagManager.js';
import { Collection } from '@discordjs/collection';
// const pkg = JSON.parse(readFileSync('../../package.json', { encoding: 'utf8' }));
@ -57,7 +57,7 @@ class Server extends EventEmitter
#server: http.Server | null;
#app: Express;
#mariadb: MariaDB;
#mariadb?: MariaDB;
#mongodb: MongoDB;
#memoryStoreProvider: MongoMemory;
#userDatabase: UserDatabaseInterface;
@ -137,6 +137,8 @@ class Server extends EventEmitter
// TODO: Database definitions should probably be elsewhere through injection
// Mariadb isn't strictly necessary here for anything, it's just here pre-emptively
if (databases.mariadb?.load)
{
this.#mariadb = new MariaDB(this, {
...databases.mariadb,
credentials: {
@ -147,6 +149,7 @@ class Server extends EventEmitter
database: MARIA_DB
}
});
}
// Mongo is used for session and user storage
this.#mongodb = new MongoDB(this, {
...databases.mongodb,
@ -243,8 +246,11 @@ class Server extends EventEmitter
const start = Date.now();
this.#logger.status('Starting server');
if (this.#mariadb)
{
this.#logger.info('Initialising MariaDB');
this.#mariadb.init();
}
this.#logger.info('Initialising MongoDB');
await this.#mongodb.init();
@ -360,7 +366,7 @@ class Server extends EventEmitter
this.#server.close(async () =>
{
await this.#mongodb.close();
await this.#mariadb.close();
await this.#mariadb?.close();
await this.#memoryStoreProvider.close();
await this.#messageBroker?.close();
this.#logger.status('DB shutdowns complete.');