-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
50 lines (42 loc) · 1.7 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
var dotenv = require('dotenv').config();
var config = require('./config/database');
var mysql = require('mysql');
var connection = mysql.createConnection(config.connection);
var express = require('express');
var session = require('cookie-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var app = express();
var nodemailer = require('nodemailer');
var schedule = require('node-schedule');
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var passport = require('passport');
var flash = require('connect-flash');
require('./helpers/socket')(io, app)
require('./config/passport.js')(passport);
app.set('port', process.env.PORT || 8000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
server.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/views'));
app.use(require("body-parser").json())
app.set('view engine', 'ejs'); // set up ejs for templating
// required for passport
app.use(session({
secret: config.keys.session_secret,
resave: true,
saveUninitialized: true
} )); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
// routes ======================================================================
require('./app/routes.js')(app, passport); // load our routes and pass in our app and fully configured passport