-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
52 lines (42 loc) · 1.35 KB
/
server.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
var express = require('express');
var session = require('express-session');
var morgan = require('morgan');
var request = require('request');
var layout = require('express-layout');
var app = express();
var GITHUB_OAUTH_ID = process.env.GITHUB_OAUTH_ID;
var GITHUB_OAUTH_SECRET = process.env.GITHUB_OAUTH_SECRET;
app.set('view engine', 'ejs');
app.set('layout', 'layout');
app.use(morgan('dev'));
app.use(session({
secret: 'thisisnotverysecret',
saveUninitialized: false,
resave: false
}));
app.use(layout());
app.use(express.static('./public'));
app.get('/', function(req, res) {
var gitHubPath = 'https://github.com/login/oauth/authorize';
res.render('index', {gitHubOauthUrl: gitHubPath});
});
app.get('/oauth_callback', function(req, res) {
res.redirect('/complete');
});
app.get('/complete', function(req, res) {
res.render('complete', {
name: 'User',
email: '[email protected]'
});
});
app.get('/logout', function(req, res) {
req.session.destroy();
res.redirect('/');
});
app.listen(9888, function() {
console.log('Server running on port 9888...');
GITHUB_OAUTH_ID ? console.log('OAuth ID acquired!') :
console.log('OAuth ID not in environment!');
GITHUB_OAUTH_SECRET ? console.log('OAuth Secret acquired!') :
console.log('OAuth Secret not in environment!');
});