-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
60 lines (45 loc) · 1.45 KB
/
app.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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const express = require('express');
const http = require('http')
const app = express();
const server = new http.createServer(app);
const path = require('path');
const session = require('./src/config/sessionConfig')
const io = require('socket.io')(server);
require('./src/modules/socketIO')(io)
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, "public/views"));
app.use(express.static(path.join(__dirname, "public")));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(session);
// CONFIG
require('./src/config/dbSchemaConfig')(); // DB SCHEMA
//HOME
const homeRouter = require('./src/routes/homeRoutes');
const { getUserDataIfLoggedIn } = require('./src/middlewares/getUserData')
app.use('/', getUserDataIfLoggedIn, homeRouter)
//ACCOUNT
const accountRouter = require('./src/routes/accountsRoutes');
app.use('/accounts', accountRouter)
//GAMES
const gamesRouter = require('./src/routes/gamesRoutes')
const { redirectUnauthorizedUser } = require('./src/middlewares/authorizations');
app.use('/games', redirectUnauthorizedUser, gamesRouter)
// app.use('/play', playRouter)
app.get("/*", (req, res) => {
res.status(404).render("home/404");
});
async function startServer(){
server.listen(process.env.PORT, (error) => {
if (error){
console.log(error)
return;
}
console.log("Server is ready!")
})
}
startServer();
module.exports = app;