mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: setup: prefer mongo connection uri
This commit is contained in:
3 files changed
+12
-41
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import {
|
||||
Collection, Db, IndexDescription, MongoClient,
|
||||
} from 'mongodb';
|
||||
import mongoUri from 'mongodb-uri';
|
||||
import { Time } from '@hydrooj/utils';
|
||||
import { Logger } from '../logger';
|
||||
import options from '../options';
|
||||
@@ -38,6 +39,7 @@ class MongoService {
|
||||
async start() {
|
||||
const opts = options() || {};
|
||||
let mongourl = MongoService.buildUrl(opts);
|
||||
const url = mongoUri.parse(mongourl);
|
||||
if (process.env.CI) {
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
const mongod = await MongoMemoryServer.create();
|
||||
@@ -45,7 +47,7 @@ class MongoService {
|
||||
}
|
||||
this.opts = opts;
|
||||
this.client = await MongoClient.connect(mongourl);
|
||||
this.db = this.client.db(opts.name || 'hydro');
|
||||
this.db = this.client.db(url.database || 'hydro');
|
||||
await bus.parallel('database/connect', this.db);
|
||||
setInterval(() => this.fixExpireAfter(), Time.hour);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user