-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
66 lines (44 loc) · 1.35 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var express = require('express'),
Sequelize = require('sequelize'),
color = require('chalk'),
bodyParser = require('body-parser'),
oauthserver = require('oauth2-server'),
load = require('express-load');
models = require("./models");
var app = express();
/*===== LOAD CONFIG, CONTROLLERS AND ROUTES ======*/
load('config')
.into(app);
/*===== CONFIG APP ======*/
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.set('env', app.config.env.mode);
app.listen('5445'); //config port
console.log('server started 127.0.0.1:5445');
/*===== CONFIG OAUTH ======*/
var dbConfig = app.config.config[app.get('env')];
var database = new Sequelize(
dbConfig.database,
dbConfig.username,
dbConfig.password, {
host : dbConfig.host,
logging : function(str) {
console.log(color.cyan( new Array(93).join('-')), '\n');
console.log(color.yellow(str), '\n');
}
});
app.oauth = oauthserver({
model: require('./OAuth2Model')(database), // See below for specification
grants: ['password'],
//debug: true
accessTokenLifetime : 604800
});
app.all('/oauth/token', app.oauth.grant());
load('routes')
.into(app);
// app.get('/test',app.oauth.authorise() ,function (req,res) {
// models.User.findAll()
// .then(function (users) {
// res.send(users);
// })
// });