-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
78 lines (67 loc) · 2.15 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
76
77
78
var express = require('express'),
bodyParser = require('body-parser'),
path = require('path'),
exphbs = require('express-handlebars'),
passport = require('passport'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
MySQLStore = require('express-mysql-session')(session),
env = require('node-env-file'),
helmet = require('helmet'),
app = express();
env('.env');
var port = process.env.PORT || 80;
// Handlabars setup
app.engine('.hbs', exphbs({
helpers: {
niceDate: function (uglyDate) {
return uglyDate.toDateString(); },
setDate: function(uglyDate) {
return uglyDate.toISOString().substr(0, 10);
}
},
defaultLayout: 'main',
extname: '.hbs'}));
app.set('view engine', '.hbs');
//Set static path
app.use("/vendors",express.static(__dirname + "/vendors"));
app.use("/build",express.static(__dirname + "/build"));
app.use("/images",express.static(__dirname + "/images"));
//More Middleware
app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(helmet());
app.use(session({
key: 'NGM Session',
secret: 'p4uuprn7HwEugArJlVMmbxXMuQYGslPos',
store: new MySQLStore({
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE,
createDatabaseTable: true,
schema: {
tableName: 'sessions',
columnNames: {
session_id: 'session_id',
expires: 'expires',
data: 'data'
}
}
}),
resave: true,
saveUninitialized: true,
}));
//Configure Passport
require('./config/passport')(passport);
app.use(passport.initialize());
app.use(passport.session());
//main.js contains routes
var main = require('./app/main.js');
app.use('/', main(express,passport));
app.listen(port, function () {
console.log('Secure Server listening on port ' + port);
});
module.exports = app;