This commit is contained in:
parent
60b0c2f577
commit
99845a7b94
@ -1,22 +1,21 @@
|
|||||||
import SafeMongo from "@hibas123/safe_mongo";
|
import SafeMongo from "@hibas123/safe_mongo";
|
||||||
import Config from "./config";
|
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) {
|
const host = Config.database.host || "localhost";
|
||||||
auth = {
|
// const port = Config.database.port || "27017";
|
||||||
username: Config.database.username,
|
const port = "27017";
|
||||||
password: Config.database.password
|
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;
|
export default DB;
|
||||||
|
Loading…
Reference in New Issue
Block a user