mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
简化模块加载
deprecated hydro-build
This commit is contained in:
1 parent
8aef05a375
commit
8f6968bbbd
41 files changed
+1361
-1957
No files matched your search
+5
-3
@@ -2,16 +2,18 @@ import mongodb from 'mongodb';
|
||||
import * as bus from './bus';
|
||||
import options from '../options';
|
||||
|
||||
const opts = options();
|
||||
|
||||
let mongourl = 'mongodb://';
|
||||
if (options.username) mongourl += `${options.username}:${options.password}@`;
|
||||
mongourl += `${options.host}:${options.port}/${options.name}`;
|
||||
if (opts.username) mongourl += `${opts.username}:${opts.password}@`;
|
||||
mongourl += `${opts.host}:${opts.port}/${opts.name}`;
|
||||
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
export let db: mongodb.Db = null;
|
||||
|
||||
mongodb.MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopology: true })
|
||||
.then((Client) => {
|
||||
db = Client.db(options.name);
|
||||
db = Client.db(opts.name);
|
||||
bus.publish('system_database_connected', null);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user