diff --git a/bundle/database.db b/bundle/database.db
new file mode 100644
index 00000000..2d4abd49
--- /dev/null
+++ b/bundle/database.db
Binary files differdiff --git a/bundle/package-lock.json b/bundle/package-lock.json
index 379b1c18..59fd96ee 100644
--- a/bundle/package-lock.json
+++ b/bundle/package-lock.json
@@ -16,6 +16,7 @@
"@fosscord/util": "file:../util",
"async-exit-hook": "^2.0.1",
"express": "^4.17.1",
+ "missing-native-js-functions": "^1.2.13",
"mongodb-memory-server": "^7.3.6",
"node-os-utils": "^1.3.5"
},
@@ -63,19 +64,22 @@
"i18next-http-middleware": "^3.1.3",
"i18next-node-fs-backend": "^2.1.3",
"jsonwebtoken": "^8.5.1",
- "lambert-server": "^1.2.8",
- "missing-native-js-functions": "^1.2.10",
+ "lambert-server": "^1.2.10",
+ "missing-native-js-functions": "^1.2.11",
"mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3",
"mongoose-long": "^0.3.2",
"multer": "^1.4.2",
- "node-fetch": "^2.6.1"
+ "node-fetch": "^2.6.1",
+ "supertest": "^6.1.6",
+ "typeorm": "^0.2.37"
},
"devDependencies": {
"@types/amqplib": "^0.8.1",
"@types/bcrypt": "^5.0.0",
"@types/express": "^4.17.9",
"@types/i18next-node-fs-backend": "^2.1.0",
+ "@types/jest": "^27.0.1",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongodb": "^3.6.9",
"@types/mongoose": "^5.10.5",
@@ -111,11 +115,13 @@
"file-type": "^16.5.0",
"fs-extra": "^10.0.0",
"image-size": "^1.0.0",
+ "jest": "^27.0.6",
"lambert-db": "^1.2.3",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.10",
"multer": "^1.4.2",
"node-fetch": "^2.6.1",
+ "supertest": "^6.1.6",
"typescript": "^4.1.2",
"uuid": "^8.3.2"
},
@@ -173,26 +179,30 @@
"hasInstallScript": true,
"license": "GPLV3",
"dependencies": {
- "ajv": "^8.5.0",
+ "ajv": "^8.6.2",
"amqplib": "^0.8.0",
+ "class-validator": "^0.13.1",
"dot-prop": "^6.0.1",
"env-paths": "^2.2.1",
"jsonwebtoken": "^8.5.1",
- "missing-native-js-functions": "^1.2.10",
- "mongodb": "^3.6.9",
- "mongoose": "^5.13.7",
- "mongoose-autopopulate": "^0.12.3",
+ "lambert-server": "^1.2.10",
+ "missing-native-js-functions": "^1.2.11",
"node-fetch": "^2.6.1",
- "typescript": "^4.1.3"
+ "patch-package": "^6.4.7",
+ "pg": "^8.7.1",
+ "reflect-metadata": "^0.1.13",
+ "sqlite3": "^5.0.2",
+ "typeorm": "^0.2.37",
+ "typescript": "^4.3.5",
+ "typescript-json-schema": "^0.50.1"
},
"devDependencies": {
"@types/amqplib": "^0.8.1",
"@types/jsonwebtoken": "^8.5.0",
- "@types/mongodb": "^3.6.9",
"@types/mongoose-autopopulate": "^0.10.1",
- "@types/mongoose-lean-virtuals": "^0.5.1",
"@types/node": "^14.17.9",
- "@types/node-fetch": "^2.5.12"
+ "@types/node-fetch": "^2.5.12",
+ "jest": "^27.0.6"
}
},
"node_modules/@babel/runtime": {
@@ -1216,6 +1226,11 @@
"node": "*"
}
},
+ "node_modules/missing-native-js-functions": {
+ "version": "1.2.13",
+ "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.13.tgz",
+ "integrity": "sha512-1RAArfUkrGkj5N3xJVW251F2PvfP2ozAcxsLLDR6uiiAixTP5Abh8zzGMadepbqgiHC0FGlTSAUNbh9abN4Osg=="
+ },
"node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
@@ -1868,6 +1883,7 @@
"@types/bcrypt": "^5.0.0",
"@types/express": "^4.17.9",
"@types/i18next-node-fs-backend": "^2.1.0",
+ "@types/jest": "^27.0.1",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongodb": "^3.6.9",
"@types/mongoose": "^5.10.5",
@@ -1899,16 +1915,18 @@
"image-size": "^1.0.0",
"jest": "^26.6.3",
"jsonwebtoken": "^8.5.1",
- "lambert-server": "^1.2.8",
- "missing-native-js-functions": "^1.2.10",
+ "lambert-server": "^1.2.10",
+ "missing-native-js-functions": "^1.2.11",
"mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3",
"mongoose-long": "^0.3.2",
"multer": "^1.4.2",
"node-fetch": "^2.6.1",
"saslprep": "^1.0.3",
+ "supertest": "^6.1.6",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6",
+ "typeorm": "^0.2.37",
"typescript": "^4.1.2"
}
},
@@ -1940,11 +1958,13 @@
"file-type": "^16.5.0",
"fs-extra": "^10.0.0",
"image-size": "^1.0.0",
+ "jest": "^27.0.6",
"lambert-db": "^1.2.3",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.10",
"multer": "^1.4.2",
"node-fetch": "^2.6.1",
+ "supertest": "^6.1.6",
"typescript": "^4.1.2",
"uuid": "^8.3.2"
}
@@ -1981,22 +2001,26 @@
"requires": {
"@types/amqplib": "^0.8.1",
"@types/jsonwebtoken": "^8.5.0",
- "@types/mongodb": "^3.6.9",
"@types/mongoose-autopopulate": "^0.10.1",
- "@types/mongoose-lean-virtuals": "^0.5.1",
"@types/node": "^14.17.9",
"@types/node-fetch": "^2.5.12",
- "ajv": "^8.5.0",
+ "ajv": "^8.6.2",
"amqplib": "^0.8.0",
+ "class-validator": "^0.13.1",
"dot-prop": "^6.0.1",
"env-paths": "^2.2.1",
+ "jest": "^27.0.6",
"jsonwebtoken": "^8.5.1",
- "missing-native-js-functions": "^1.2.10",
- "mongodb": "^3.6.9",
- "mongoose": "^5.13.7",
- "mongoose-autopopulate": "^0.12.3",
+ "lambert-server": "^1.2.10",
+ "missing-native-js-functions": "^1.2.11",
"node-fetch": "^2.6.1",
- "typescript": "^4.1.3"
+ "patch-package": "^6.4.7",
+ "pg": "^8.7.1",
+ "reflect-metadata": "^0.1.13",
+ "sqlite3": "^5.0.2",
+ "typeorm": "^0.2.37",
+ "typescript": "^4.3.5",
+ "typescript-json-schema": "^0.50.1"
}
},
"@types/amqplib": {
@@ -2784,6 +2808,11 @@
"brace-expansion": "^1.1.7"
}
},
+ "missing-native-js-functions": {
+ "version": "1.2.13",
+ "resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.13.tgz",
+ "integrity": "sha512-1RAArfUkrGkj5N3xJVW251F2PvfP2ozAcxsLLDR6uiiAixTP5Abh8zzGMadepbqgiHC0FGlTSAUNbh9abN4Osg=="
+ },
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
diff --git a/bundle/package.json b/bundle/package.json
index 38377d15..63945135 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",
@@ -50,6 +51,7 @@
"@fosscord/util": "file:../util",
"async-exit-hook": "^2.0.1",
"express": "^4.17.1",
+ "missing-native-js-functions": "^1.2.13",
"mongodb-memory-server": "^7.3.6",
"node-os-utils": "^1.3.5"
}
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");
|