mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 16:33:30 +08:00
ea2ee68ed6
* Adding headers to stream request. * Switching mongodb when node_env === test.
26 lines
523 B
JavaScript
26 lines
523 B
JavaScript
const mongoose = require('mongoose');
|
|
const debug = require('debug')('talk:db');
|
|
const enabled = require('debug').enabled;
|
|
let url = process.env.TALK_MONGO_URL || 'mongodb://localhost';
|
|
|
|
if (process.env.NODE_ENV === 'test') {
|
|
url = 'mongodb://localhost/coral-test';
|
|
}
|
|
|
|
// Use native promises
|
|
mongoose.Promise = global.Promise;
|
|
|
|
if (enabled('talk:db')) {
|
|
mongoose.set('debug', true);
|
|
}
|
|
|
|
mongoose.connect(url, (err) => {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
|
|
debug('connection established');
|
|
});
|
|
|
|
module.exports = mongoose;
|