-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
102 lines (81 loc) · 2.26 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var express = require('express');
var stormpath = require('express-stormpath');
var dbConf = require('./configs/default').db;
var userConf = require('./configs/default').apiKey;
var sessionConf = require('./configs/default').session;
var mongoose = require('mongoose');
var express_session = require('express-session');
var MongoStore = require('connect-mongo')(express_session);
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var passport = require('passport');
var routes = require('./routes');
var cookieSession = require('cookie-session');
// var csurf = require('csurf');
var app = express();
app.set('views', './views');
app.set('view engine', 'html');
app.engine("html", require("ejs").__express);
app.use(express.static('public'));
/**
* Middleware
* Session
*/
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.use(cookieParser());
app.use(express_session({
"store": new MongoStore({
url: dbConf.url,
host: dbConf.host,
port: dbConf.port,
db: dbConf.dbname
})
, "secret": sessionConf.secret
, "key": sessionConf.key
, "cookie": {"maxAge": sessionConf.timeout * 60 * 60 * 1000}
, saveUninitialized: true
, resave: true
}));
// app.use(cookieSession({
// name: 'session',
// keys: ['key1', 'key2']
// }));
// app.use(csurf({ cookie: true }))
app.use(passport.initialize());
app.use(passport.session());
//TODO error handler
app.use(stormpath.init(app, {
expand: {
debug: 'info',
customData: true
},
apiKey: {
id: userConf.STORMPATH_CLIENT_APIKEY_ID,
secret: userConf.STORMPATH_CLIENT_APIKEY_SECRET
},
application: {
href: userConf.STORMPATH_APPLICATION_HREF
},
web: {
login: {
enabled: true,
nextUri: "/home"
},
logout: {
enabled: true,
uri: '/logout',
nextUri: '/login'
}
}
}));
routes(app);
console.log("Please waitting . . .");
app.on('stormpath.ready',function(){
console.log('Stormpath Ready');
app.listen(3000);
console.log("Sognare listening on port %d ", 3000);
});
module.exports = app;