-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
86 lines (69 loc) · 2.14 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
var awsParamStore = require('aws-param-store');
var express = require('express');
var app = express();
var path = require('path');
var exphbs = require('express-handlebars');
var session = require('express-session');
let db = require('./db/db');
var find = require('lodash/find');
var logger = require('./logger');
logger.log('info', "Server started");
// view engine setup
app.engine('.hbs', exphbs({
extname: '.hbs',
defaultLayout: null
}));
app.set('view engine', '.hbs');
app.set('trust proxy', 1) // trust first proxy
app.get('/ping', function (req, res) { //for aws healthcheck
res.send('dong!')
})
let SequelizeStore = require('connect-session-sequelize')(session.Store);
let myStore = new SequelizeStore({
db: db.sequalize
})
const parameters = awsParamStore.getParametersByPathSync('/', { region: 'us-east-1' })
const SESSION_SECRET = find(parameters, ['Name', 'SESSION_SECRET']).Value
app.use(session({
name: 'sessionId',
secret: SESSION_SECRET,
store: myStore,
resave: false,
saveUninitialized: false,
proxy: true,
cookie: {
secure: true,
httpOnly: false,
domain: 'buypixels.net',
path: '/',
expires: new Date((Date.now() + ((60 * 60 /*one hour*/ ) * 24 /*one day*/ ) * 1000) * 5) //
}
}))
//myStore.sync();
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
//web routes
require('./routes/web/auth.js')(app);
require('./routes/web/auth/email')(app);
require('./routes/web/index.js')(app);
require('./routes/web/market.js')(app);
require('./routes/web/user.js')(app);
//routes vars
//user routes vars
var userApiRoutes = require('./routes/api/users');
var userAuthApiRoutes = require('./routes/api/users/auth');
var botsApiRoutes = require('./routes/api/bots');
//routes
//user routes
app.use('/webAPI/users', userApiRoutes);
app.use('/webAPI/usersAuth', userAuthApiRoutes);
//bot routes
app.use('/webAPI/bots', botsApiRoutes);
app.all('*', function (req, res, next) {
if (req.secure) {
return next();
}
res.redirect('https://' + req.hostname + req.url);
});
//asdf
app.listen(3000);