-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (54 loc) · 1.81 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
const express = require('express');
var bodyParser = require('body-parser');
var session = require('express-session');
const path = require('path');
const PORT = process.env.PORT || 3001;
const app = express();
var server = require('http').createServer(app);
var io = (module.exports.io = require('socket.io')(server));
// var io = module.exports.io = require('socket.io').listen(server);
// <-- include either the top or bottom -->
// var io = require('socket.io').listen(server);
users = [];
connections = [];
const SocketManager = require('./SocketManager.js');
io.on('connection', SocketManager);
const db = require('./models');
// Define middleware here
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(
session({
secret: 'kevAidDavVer',
resave: false,
saveUninitialized: true,
cookie: { secure: 'auto', maxAge: 99999 },
}),
);
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
}
// Define API routes here
const routes = require('./routes/api.js');
app.use(routes);
const loginSystem = require('./routes/loginSystem.js');
app.use(loginSystem);
const votingSystem = require('./routes/votingSystem.js');
app.use(votingSystem);
const emailSystem = require('./routes/emailSystem.js');
app.use(emailSystem);
const mentorSystem = require('./routes/mentorSystem.js');
app.use(mentorSystem);
// Send every other request to the React app
// Define any API routes before this runs
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, './client/build/index.html'));
});
db.sequelize.sync({ force: false }).then(function() {
server.listen(PORT, () => {
console.log(`🌎 ==> Server now on port ${PORT}!`);
});
});