optional loading of mariadb
This commit is contained in:
parent
2f11ffa08a
commit
3c8688ee34
@ -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,16 +137,19 @@ 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
|
||||
this.#mariadb = new MariaDB(this, {
|
||||
...databases.mariadb,
|
||||
credentials: {
|
||||
host: MARIA_HOST,
|
||||
user: MARIA_USER,
|
||||
port: parseInt(MARIA_PORT),
|
||||
password: MARIA_PASS,
|
||||
database: MARIA_DB
|
||||
}
|
||||
});
|
||||
if (databases.mariadb?.load)
|
||||
{
|
||||
this.#mariadb = new MariaDB(this, {
|
||||
...databases.mariadb,
|
||||
credentials: {
|
||||
host: MARIA_HOST,
|
||||
user: MARIA_USER,
|
||||
port: parseInt(MARIA_PORT),
|
||||
password: MARIA_PASS,
|
||||
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');
|
||||
|
||||
this.#logger.info('Initialising MariaDB');
|
||||
this.#mariadb.init();
|
||||
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.');
|
||||
|
Loading…
Reference in New Issue
Block a user