-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (31 loc) · 950 Bytes
/
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
require('dotenv').config();
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const passport = require('passport');
const app = express();
const events = require('./events/index');
const oauth = require('./oauth/index');
app.use(session({
secret: 'anything',
resave: false,
saveUninitialized: false
}));
app.use(bodyParser.json());
app.use(passport.initialize());
app.use(passport.session());
app.use(`${process.env.SERVER_EVENTS_PATH}`, events);
app.use(`${process.env.SERVER_OAUTH_PATH}`, oauth);
app.get('/', (req, res) => {
if (req.isAuthenticated()) {
res.send(`Authed as: ${req.user.username}, ${req.user.displayName}`);
} else {
res.redirect('/oauth/github');
}
});
app.listen(process.env.SERVER_PORT || 3000, err => {
if (err) {
throw error;
}
console.log(`Server is running on localhost:${process.env.SERVER_PORT || 3000}`);
});