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", "mime-types": "2.1.14",
"mocha": "3.2.0", "mocha": "3.2.0",
"mongodb": "2.2.21", "mongodb": "2.2.21",
"mongoskin": "^2.1.0",
"ms": "0.7.2", "ms": "0.7.2",
"multer": "1.2.1", "multer": "1.2.1",
"nprogress": "0.2.0", "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('token');
collection.createIndex('hash'); 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');
collection.createIndex('name_id_lower'); 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 { export function validateFileName(name: string): boolean {
return ( 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 { export function isValidFolderName(name: string): boolean {
return ( 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('username');
collection.createIndex('token'); collection.createIndex('token');

View File

@ -1,8 +1,11 @@
import * as mongodb from 'mongodb'; const mongo = require('mongoskin');
import config from '../conf';
export default async function(): Promise<mongodb.Db> {
const uri = config.mongodb.user && config.mongodb.pass 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.user}:${config.mongodb.pass}@${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}`
: `mongodb://${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);
}; 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 portUsed = require('tcp-port-used');
import isRoot = require('is-root'); import isRoot = require('is-root');
import ProgressBar from './utils/cli/progressbar'; import ProgressBar from './utils/cli/progressbar';
import initdb from './db/mongodb';
import LastCommitInfo from './utils/lastCommitInfo'; import LastCommitInfo from './utils/lastCommitInfo';
import EnvironmentInfo from './utils/environmentInfo'; import EnvironmentInfo from './utils/environmentInfo';
import MachineInfo from './utils/machineInfo'; import MachineInfo from './utils/machineInfo';
@ -106,16 +105,8 @@ async function masterMain(): Promise<void> {
* Init worker proccess * Init worker proccess
*/ */
function workerMain(): void { function workerMain(): void {
// Init mongo
initdb().then(db => {
global.db = db;
// start server // start server
require('./server'); require('./server');
}, err => {
console.error(err);
process.exit(0);
});
} }
/** /**
@ -158,7 +149,7 @@ async function init(): Promise<InitResult> {
// Try to connect to MongoDB // Try to connect to MongoDB
let mongoDBLogger = new Logger('MongoDB'); let mongoDBLogger = new Logger('MongoDB');
try { try {
const db = await initdb(); const db = require('./db/mongodb').default;
mongoDBLogger.info('Successfully connected'); mongoDBLogger.info('Successfully connected');
db.close(); db.close();
} catch (e) { } catch (e) {