This repository has been archived by the owner on Jul 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (67 loc) · 2.07 KB
/
index.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
require('dotenv').load();
var express = require('express');
var expressHbs = require('express-handlebars');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var expressSession = require('express-session');
var passport = require('passport');
var GitHubStrategy = require('passport-github').Strategy;
var app = express();
var port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser(process.env.SESSION_SECRET));
app.use(expressSession({
secret : process.env.SESSION_SECRET,
cookie : {
expires: false,
},
resave: true,
saveUninitialized: true
}));
// Authentication
app.use(passport.initialize());
app.use(passport.session());
passport.use(new GitHubStrategy({
clientID: process.env.GH_KEY,
clientSecret: process.env.GH_SECRET,
callbackURL: '/auth/github/callback',
scope: ['repo', 'write:repo_hook']
},
function(accessToken, refreshToken, profile, done) {
return done(null, {profile: profile, token: accessToken});
})
);
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
// Render engine
app.engine('handlebars', expressHbs.create({defaultLayout:'main'}).engine);
app.set('view engine', 'handlebars');
app.use(express.static(__dirname + '/public'));
// Controllers
app.use(require('./controllers'));
app.use(require('./controllers/auth'));
app.use(require('./controllers/setup'));
app.use(require('./controllers/pullrequest'));
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found (' + req.url + ')');
err.status = 404;
next(err);
});
// production error handler no stacktraces leaked to user
app.use(function(err, req, res) {
res.status(err.status || 500);
res.render('error', {
status: err.status || 500,
message: err.message,
error: {}
});
});
app.listen(port, function(){
console.log('Listening on ' + port);
});