-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.27 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
'use strict';
require('dotenv').config();
const path = require('path')
const express = require('express')
const passport = require('passport')
const { Strategy } = require('passport-twitter')
const { TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, SESSION_SECRET } = process.env;
const port = process.env.PORT || 3000;
const app = express();
const routes = require('./routes');
// configure the Twitter strategy for use by Passport.
passport.use(new Strategy({
consumerKey: TWITTER_CONSUMER_KEY,
consumerSecret: TWITTER_CONSUMER_SECRET,
callbackURL: '/return'
},
(accessToken, refreshToken, profile, cb) => {
return cb(null, profile);
}));
// configure Passport authenticated session persistence.
passport.serializeUser((user, cb) => {
cb(null, user);
});
passport.deserializeUser((obj, cb) => {
cb(null, obj);
});
// tempalte engine
app.set('view engine', 'ejs');
app.use('/public', express.static(path.join(__dirname, 'public')));
// session handling
app.use(require('express-session')({ secret: SESSION_SECRET, resave: true, saveUninitialized: true }));
// initialize Passport and restore authentication state, if any, from the session.
app.use(passport.initialize());
app.use(passport.session());
// routes directory
app.use('/', routes);
app.listen(port);