-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-server.js
55 lines (45 loc) · 1.37 KB
/
node-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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var db = require('./api/database');
var session = require('express-session');
var Brute = require('./api/middleware/bruteforce');
app.enable('trust proxy');
app.disable('x-powered-by');
var MongoDBStore = require('connect-mongodb-session')(session);
var store = new MongoDBStore({
uri: 'mongodb://localhost:27017/splusgg',
collection: 'sessions'
});
store.on('error', function(error) {
console.log('mstore error!', error);
});
app.use(session({
name: 'sgg',
secret: 'supersecretysecret45',
cookie: { secure: 'auto' },
store: store
}));
//Routers
var RiotRouter = require('./routes/riotroutes.js');
var TwitchRouter = require('./routes/twitchroutes.js');
//Fowarding from EXPRESS <-- NGINX <-- CF <-- Load Balancing IP <--- INTERNET
app.use(function(req, res, next) {
req.locals = {};
req.locals.store = store;
next();
})
if(process.env.ENV === 'production') {
console.log('ENV=production, Serving from Dist Folder!');
app.use('/', express.static('dist'));
}
else {
app.use('/', express.static('client'));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(process.env.PORT || 3005, function() {
console.log('Server Started!');
});
app.use('/riot/', RiotRouter, Brute); //Rate limit global riot api
app.use('/twitch/', TwitchRouter);