-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
57 lines (50 loc) · 1.84 KB
/
server.js
File metadata and controls
57 lines (50 loc) · 1.84 KB
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
// Requiring Utilities
// =============================================================
const express = require('express');
const session = require('express-session');
const exphbs = require('express-handlebars');
const sequelize = require("./config/connection.js");
const SequelizeStore = require('connect-session-sequelize')(session.Store);
const routes = require("./controllers");
const { createServer } = require('http');
const { Server } = require('socket.io');
const { User, } = require('./models');
// Sets up the Express/Socket App
// =============================================================
const app = express();
const socketServer = require('./controllers/socketServer');
const httpServer = createServer(app);
const io = new Server(httpServer);
socketServer(io);
const PORT = process.env.PORT || 3000;
// Declaring Sessions
// =============================================================
const sess = {
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true,
store: new SequelizeStore({
db: sequelize
})
};
app.use(session(sess));
// Sets up the Express app to handle data parsing
// =============================================================
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Static directory and Custom Routes
// =============================================================
app.use(express.static('public'));
app.use("/", routes);
// Initializing handlebars
// =============================================================
const hbs = exphbs.create({});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
// Running Server
// =============================================================
sequelize.sync({ force: false }).then(function() {
httpServer.listen(PORT, function() {
console.log('App listening on PORT ' + PORT);
});
});