From 99845a7b94b3591f8fb6bb9675027344426f96ed Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Wed, 29 Nov 2023 13:32:57 +0100 Subject: [PATCH] Try different URL schema --- Backend/src/database.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Backend/src/database.ts b/Backend/src/database.ts index b709884..08104e4 100644 --- a/Backend/src/database.ts +++ b/Backend/src/database.ts @@ -1,22 +1,21 @@ import SafeMongo from "@hibas123/safe_mongo"; import Config from "./config"; -let dbname = "openauth"; -let host = "localhost"; -if (Config.database) { - if (Config.database.database) dbname = Config.database.database; - if (Config.database.host) host = Config.database.host; -} -if (Config.core.dev) dbname += "_dev"; -let auth = undefined; -if (Config.database.username) { - auth = { - username: Config.database.username, - password: Config.database.password - } + +const host = Config.database.host || "localhost"; +// const port = Config.database.port || "27017"; +const port = "27017"; +const database = Config.database.database || "openauth"; +const url = new URL(`mongodb://${host}:${port}/${database}`); + +const user = Config.database.username || undefined; +const passwd = Config.database.password || undefined; + +if (user) { + url.username = user; + if (passwd) url.password = passwd; } -const DB = new SafeMongo("mongodb://" + host, dbname, { - auth -}); + +const DB = new SafeMongo(url.href, database); export default DB;