From b68b1a118144baaef7da849ad7d42767401cad01 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 29 Aug 2021 16:58:53 +0200 Subject: fix bundle --- bundle/src/Database.ts | 44 -------------------------------------------- bundle/src/Server.ts | 4 +++- bundle/src/start.ts | 2 -- 3 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 bundle/src/Database.ts (limited to 'bundle/src') diff --git a/bundle/src/Database.ts b/bundle/src/Database.ts deleted file mode 100644 index 12febc1c..00000000 --- a/bundle/src/Database.ts +++ /dev/null @@ -1,44 +0,0 @@ -import fs from "fs"; -import { MongoMemoryServer } from "mongodb-memory-server"; -import path from "path"; -import exitHook from "async-exit-hook"; - -if (process.arch == "ia32") { - Object.defineProperty(process, "arch", { - value: "x64", - }); -} - -export async function setupDatabase() { - if (process.env.MONGO_URL) return; // exit because the user provides his own mongodb - const dbPath = path.join(__dirname, "..", "..", "db"); - const dbName = "fosscord"; - const storageEngine = "wiredTiger"; - const port = 27020; - const ip = "127.0.0.1"; - var mongod: MongoMemoryServer; - fs.mkdirSync(dbPath, { recursive: true }); - - exitHook((callback: any) => { - (async () => { - console.log(`Stopping MongoDB ...`); - await mongod.stop(); - console.log(`Stopped MongoDB`); - callback(); - })(); - }); - - console.log(`[Database] starting ...`); - mongod = new MongoMemoryServer({ - instance: { - port, - ip, - dbName, - dbPath, - storageEngine, - auth: false, // by default `mongod` is started with '--noauth', start `mongod` with '--auth' - }, - }); - await mongod.start(); - process.env.MONGO_URL = mongod.getUri(dbName); -} diff --git a/bundle/src/Server.ts b/bundle/src/Server.ts index e0586601..56c82cd1 100644 --- a/bundle/src/Server.ts +++ b/bundle/src/Server.ts @@ -6,7 +6,7 @@ import { FosscordServer as APIServer } from "@fosscord/api"; import { Server as GatewayServer } from "@fosscord/gateway"; import { CDNServer } from "@fosscord/cdn/"; import express from "express"; -import { Config } from "@fosscord/util"; +import { Config, initDatabase } from "@fosscord/util"; const app = express(); const server = http.createServer(); @@ -22,6 +22,8 @@ const cdn = new CDNServer({ server, port, production, app }); const gateway = new GatewayServer({ server, port, production }); async function main() { + await initDatabase(); + await Config.init(); await Config.set({ cdn: { endpointClient: "${location.host}", diff --git a/bundle/src/start.ts b/bundle/src/start.ts index 323995ae..843e3812 100644 --- a/bundle/src/start.ts +++ b/bundle/src/start.ts @@ -1,7 +1,6 @@ // process.env.MONGOMS_DEBUG = "true"; import cluster from "cluster"; import os from "os"; -import { setupDatabase } from "./Database"; import { initStats } from "./stats"; // TODO: add tcp socket event transmission @@ -12,7 +11,6 @@ if (cluster.isMaster && !process.env.masterStarted) { (async () => { initStats(); - await setupDatabase(); if (cores === 1) { require("./Server.js"); -- cgit 1.5.1