-
Notifications
You must be signed in to change notification settings - Fork 24
/
server.js
executable file
·75 lines (62 loc) · 2.02 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const fs = require('fs'),
https = require('https'),
express = require('express'),
Session = require('express-session'),
FileStore = require('session-file-store')(Session),
fileUpload = require('express-fileupload'),
bodyParse = require('body-parser'),
passport = require('./auth/passport'),
mongoose = require('mongoose'),
FB = require('fb'),
config = require('config'),
middleware = require('connect-ensure-login'),
scheduler = require('./cron/scheduler'),
options = {
key: fs.readFileSync(__dirname + '/certs/selfsigned.key'),
cert: fs.readFileSync(__dirname + '/certs/selfsigned.crt'),
},
port = 8888;
FB.options({
appId: config.get('appId'),
appSecret: config.get('appSecret')
});
const app = express();
mongoose.connect('mongodb://127.0.0.1/nodeFB');
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use('/src', express.static(__dirname + '/public'));
app.use('/media', express.static(__dirname + '/media'));
app.use(fileUpload());
app.use(require('morgan')('combined'));
app.use(require('cookie-parser')());
app.use(bodyParse.urlencoded({extended: true}));
app.use(bodyParse.json());
app.use(Session({
store: new FileStore(),
secret: config.get('sessionSecret'),
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use('/', require('./routes/scheduler'));
app.use('/login', require('./routes/login'));
app.get('/',
function (req, res) {
res.render('app', {user: req.user});
});
app.get('/logout',
middleware.ensureLoggedIn(),
(req, res) => {
req.session.destroy();
res.redirect('/');
});
app.get('*',
middleware.ensureLoggedIn(),
function (req, res) {
res.render('app', {user: req.user});
});
scheduler();
https.createServer(options, app).listen(port, function(){
console.log("Express server listening on port " + port);
});