-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (41 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
var express = require('express'),
config = require('./config/config'),
glob = require('glob'),
mongoose = require('mongoose'),
helmet = require('helmet');
var session = require('express-session')
var passport = require('passport'); // Passport: Node's Middleware for users login
// passport configuration
require('./app/models/user');
require('./passport')(passport);
mongoose.connect(config.db);
var db = mongoose.connection;
db.on('error', function () {
throw new Error('unable to connect to database at ' + config.db);
});
var models = glob.sync(config.root + '/app/models/*.js');
models.forEach(function (model) {
require(model);
});
var app = express();
app.use(helmet());
// use sessions
app.use(session({ secret: 'lollllo', cookie: { maxAge: 15 * 24 * 60 * 60 * 1000 } }));
// Passport config
app.use(passport.initialize());
app.use(passport.session());
// Passport routes
app.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
// Twitter login
app.get('/auth/twitter', passport.authenticate('twitter'));
// Callback after Twitter login
app.get('/auth/twitter/callback', passport.authenticate('twitter',
{ successRedirect: '/', failureRedirect: '/' }
));
module.exports = require('./config/express')(app, config);
app.listen(config.port, function () {
console.log('Express server listening on port ' + config.port);
});