-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
48 lines (42 loc) · 1.11 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* db.js
* attempt to connect to mongodb
* then, load all models into mongoose
*/
'use strict';
var mongoose = require('mongoose');
var bcrypt = require('bcryptjs');
var config = require('./config');
// load models into mongoose
var models = require('./models');
var Client = require('./models/Client');
// attempt connection
mongoose.connect(config.database.URL);
var connection = mongoose.connection;
connection.on('error', console.error.bind(
console
, 'connection error:'
));
connection.once('open', function() {
console.log('connected to database');
Client.remove({}, function(err) {
var web_client = new Client({
name: "Web API v1",
client_id: config.auth.clients.web,
secret: config.auth.keys.oauth_clients.web
});
var ios_client = new Client({
name: "IOS API v1",
client_id: config.auth.clients.ios,
secret: config.auth.keys.oauth_clients.ios
});
var android_client = new Client({
name: "Android API v1",
client_id: config.auth.clients.android,
secret: config.auth.keys.oauth_clients.android
});
web_client.save();
ios_client.save();
android_client.save();
});
});