forked from FoundKeyGang/FoundKey
✌️
This commit is contained in:
parent
52af143a41
commit
87d14a9545
18 changed files with 59 additions and 34 deletions
|
@ -108,6 +108,7 @@
|
|||
"mime-types": "2.1.14",
|
||||
"mocha": "3.2.0",
|
||||
"mongodb": "2.2.21",
|
||||
"mongoskin": "^2.1.0",
|
||||
"ms": "0.7.2",
|
||||
"multer": "1.2.1",
|
||||
"nprogress": "0.2.0",
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
const collection = global.db.collection('access_tokens');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
const collection = db.collection('access_tokens');
|
||||
|
||||
collection.createIndex('token');
|
||||
collection.createIndex('hash');
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
const collection = global.db.collection('apps');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
const collection = db.collection('apps');
|
||||
|
||||
collection.createIndex('name_id');
|
||||
collection.createIndex('name_id_lower');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('appdata');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('appdata');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('auth_sessions');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('auth_sessions');
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
export default global.db.collection('drive_files');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('drive_files');
|
||||
|
||||
export function validateFileName(name: string): boolean {
|
||||
return (
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
export default global.db.collection('drive_folders');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('drive_folders');
|
||||
|
||||
export function isValidFolderName(name: string): boolean {
|
||||
return (
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('drive_tags');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('drive_tags');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('favorites');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('favorites');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('following');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('following');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('likes');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('likes');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('messaging_histories');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('messaging_histories');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('messaging_messages');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('messaging_messages');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('posts');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('posts');
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default global.db.collection('signin');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.collection('signin');
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
const collection = global.db.collection('users');
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
const collection = db.collection('users');
|
||||
|
||||
collection.createIndex('username');
|
||||
collection.createIndex('token');
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import * as mongodb from 'mongodb';
|
||||
const mongo = require('mongoskin');
|
||||
|
||||
export default async function(): Promise<mongodb.Db> {
|
||||
const uri = config.mongodb.user && config.mongodb.pass
|
||||
? `mongodb://${config.mongodb.user}:${config.mongodb.pass}@${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}`
|
||||
: `mongodb://${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}`;
|
||||
return await mongodb.MongoClient.connect(uri);
|
||||
};
|
||||
import config from '../conf';
|
||||
|
||||
const uri = config.mongodb.user && config.mongodb.pass
|
||||
? `mongodb://${config.mongodb.user}:${config.mongodb.pass}@${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}`
|
||||
: `mongodb://${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}`;
|
||||
|
||||
const db = mongo.db(uri, { native_parser: true });
|
||||
|
||||
export default db;
|
||||
|
|
15
src/index.ts
15
src/index.ts
|
@ -15,7 +15,6 @@ import * as chalk from 'chalk';
|
|||
import portUsed = require('tcp-port-used');
|
||||
import isRoot = require('is-root');
|
||||
import ProgressBar from './utils/cli/progressbar';
|
||||
import initdb from './db/mongodb';
|
||||
import LastCommitInfo from './utils/lastCommitInfo';
|
||||
import EnvironmentInfo from './utils/environmentInfo';
|
||||
import MachineInfo from './utils/machineInfo';
|
||||
|
@ -106,16 +105,8 @@ async function masterMain(): Promise<void> {
|
|||
* Init worker proccess
|
||||
*/
|
||||
function workerMain(): void {
|
||||
// Init mongo
|
||||
initdb().then(db => {
|
||||
global.db = db;
|
||||
|
||||
// start server
|
||||
require('./server');
|
||||
}, err => {
|
||||
console.error(err);
|
||||
process.exit(0);
|
||||
});
|
||||
// start server
|
||||
require('./server');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,7 +149,7 @@ async function init(): Promise<InitResult> {
|
|||
// Try to connect to MongoDB
|
||||
let mongoDBLogger = new Logger('MongoDB');
|
||||
try {
|
||||
const db = await initdb();
|
||||
const db = require('./db/mongodb').default;
|
||||
mongoDBLogger.info('Successfully connected');
|
||||
db.close();
|
||||
} catch (e) {
|
||||
|
|
Loading…
Reference in a new issue