-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
101 lines (85 loc) · 2.05 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import 'babel-polyfill';
// express
import express from 'express';
//helmet
import helmet from 'helmet';
//morgan
import morgan from 'morgan';
//Passport
import passport from './library/Passport/Passport';
// express connect redis
import redis from 'redis';
// body parser
import bodyParser from 'body-parser';
//cors
import cors from 'cors';
// socketio
import {setup} from './socketio/io';
import {loadRouters} from './routers/RouterLoader';
// start app
const app = express();
// Configure out environment to be available.
require('dotenv').config();
/**
* Redis Store Configuration
*/
let redisHost = '';
process.env.ENVIROMENT === 'development' ? redisHost = '109.237.26.131' : 'localhost';
let session = require('express-session');
let redisStore = require('connect-redis')(session);
let client = redis.createClient({host: 'localhost', port: 6379});
/**\
* Reddis Sessions
*/
app.use(session({
secret: 'ssshhhhh',
// create new redis store.
store: new redisStore({host: 'localhost', port: 6379, client: client, ttl: 260}),
saveUninitialized: false,
resave: true
}));
client.on('connect', () => {
console.log('Connected to Redis');
});
client.on('error', (err) => {
console.log('Redis error: ' + err);
});
/**
* Port Configuration
*/
let port = 3000;
process.env.ENVIROMENT === 'development' ? port = 3000 : port = 8080;
// Setup the socketio api module
setup(app);
/**
* Integrate helmet for mitigation of various attacks.
*/
app.use(helmet());
/**
* Integrate morgan for developer friendly logs of http requests.
*/
app.use(morgan('dev'));
/**
* CORS
*/
app.use(cors());
/**
* body parser
*/
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
/**
* Passport JWT
*/
let configuredPassport = new passport();
// Only configure the passport once.
configuredPassport.configurePassport();
app.use(configuredPassport.passport.initialize());
app.use(configuredPassport.passport.session());
// Load routers
loadRouters(app);
app.listen(port, () => {
console.log('Http Server listening on ', port);
});