-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.js
72 lines (59 loc) · 1.99 KB
/
serve.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
/*
This file is part of cslicer-cloud.
cslicer-cloud is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License
along with cslicer-cloud. If not, see <http://www.gnu.org/licenses/>.
*/
var express = require('express')
var mustacheExpress = require('mustache-express');
var passport = require('passport');
var session = require('express-session');
var config = require('./config/config.js');
// load the auth variables
var configAuth = require('./config/auth.js');
var routes = require('./routes/index.js');
var app = express();
var GitHubStrategy = require('passport-github2').Strategy;
// required for passport
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
passport.use(new GitHubStrategy({
clientID: configAuth.githubAuth.clientID,
clientSecret: configAuth.githubAuth.clientSecret,
callbackURL: configAuth.githubAuth.callbackURL,
}, function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// github.authenticate({
// type: "oauth",
// OA token: accessToken
// });
return done(null, profile);
});
}));
app.use(session({
secret: 'keyboard cat', resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(express.static(__dirname + '/public'));
app.engine('html', mustacheExpress());
app.set('view engine', 'mustache');
app.set('views', __dirname + '/views');
app.use('', routes);
// logging
app.use(function(req, res, next) {
console.log('%s %s %s', req.method, req.url, req.path);
next();
});
app.listen(config.port, function () {
console.log('Listening on port ' + config.port);
});