-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (41 loc) · 1.37 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
var express = require('express');
var session = require('express-session');
var cacheConfig = require('./db/cacheconfig')(session);
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var user = require('./model/user');
var everyauth = require('everyauth');
var fs = require('fs');
var credentials = JSON.parse(fs.readFileSync('./github.credentials.encrypted', 'UTF-8'));
everyauth.github
.appId(credentials['appId'])
.appSecret(credentials['appSecret'])
.scope('user')
.findOrCreateUser(function(session, accessToken, accessTokenSecret, githubUserData) {
var promise = this.Promise();
user.authenticateUser(accessToken, accessTokenSecret, githubUserData, promise);
return promise;
})
.handleAuthCallbackError( function (req, res) {
console.log('auth callback error');
})
.redirectPath('/');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser('appfogv2'));
app.use(express.static(path.join(__dirname, 'public')));
//everyauth
app.use(session({
store: cacheConfig.getRedisStore(),
secret: 'appfogv2'
}));
app.use(everyauth.middleware());
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
//setup routes
app.use(app.router);
require('./routes')(app);
module.exports = app;