diff --git a/bundle/database.db b/bundle/database.db new file mode 100644 index 00000000..9572c45e Binary files /dev/null and b/bundle/database.db differ diff --git a/bundle/package-lock.json b/bundle/package-lock.json index 379b1c18..9fcb5490 100644 Binary files a/bundle/package-lock.json and b/bundle/package-lock.json differ diff --git a/bundle/package.json b/bundle/package.json index 38377d15..71d7efea 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -5,8 +5,9 @@ "main": "src/start.js", "scripts": { "preinstall": "cd ../util && npm i && cd ../api && npm i && cd ../cdn && npm i && cd ../gateway && npm i", - "build": "npm run build:api && npm run build:cdn && npm run build:gateway && npm run build:bundle", + "build": "npm run build:util && npm run build:api && npm run build:cdn && npm run build:gateway && npm run build:bundle", "build:bundle": "npx tsc -b .", + "build:util": "cd ../util/ && npm run build", "build:api": "cd ../api/ && npm run build", "build:cdn": "cd ../cdn/ && npm run build", "build:gateway": "cd ../gateway/ && npm run build", 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");