import SafeMongo from "@hibas123/safe_mongo";
import Config from "./config.js";


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(url.href, database);
export default DB;
