This commit is contained in:
syuilo 2017-01-17 09:12:33 +09:00
parent 52af143a41
commit 87d14a9545
18 changed files with 59 additions and 34 deletions

View file

@ -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",

View file

@ -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');

View file

@ -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');

View file

@ -1 +1,3 @@
export default global.db.collection('appdata');
import db from '../../db/mongodb';
export default db.collection('appdata');

View file

@ -1 +1,3 @@
export default global.db.collection('auth_sessions');
import db from '../../db/mongodb';
export default db.collection('auth_sessions');

View file

@ -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 (

View file

@ -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 (

View file

@ -1 +1,3 @@
export default global.db.collection('drive_tags');
import db from '../../db/mongodb';
export default db.collection('drive_tags');

View file

@ -1 +1,3 @@
export default global.db.collection('favorites');
import db from '../../db/mongodb';
export default db.collection('favorites');

View file

@ -1 +1,3 @@
export default global.db.collection('following');
import db from '../../db/mongodb';
export default db.collection('following');

View file

@ -1 +1,3 @@
export default global.db.collection('likes');
import db from '../../db/mongodb';
export default db.collection('likes');

View file

@ -1 +1,3 @@
export default global.db.collection('messaging_histories');
import db from '../../db/mongodb';
export default db.collection('messaging_histories');

View file

@ -1 +1,3 @@
export default global.db.collection('messaging_messages');
import db from '../../db/mongodb';
export default db.collection('messaging_messages');

View file

@ -1 +1,3 @@
export default global.db.collection('posts');
import db from '../../db/mongodb';
export default db.collection('posts');

View file

@ -1 +1,3 @@
export default global.db.collection('signin');
import db from '../../db/mongodb';
export default db.collection('signin');

View file

@ -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');

View file

@ -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;

View file

@ -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) {