forked from cmda-minor-web/real-time-web-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (59 loc) · 1.83 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
61
62
63
64
65
66
const http = require('http')
const compression = require('compression')
const express = require('express') // Express web server framework
const handlebars = require('express-handlebars')
const session = require('express-session')
const cors = require('cors')
const cookieParser = require('cookie-parser')
if(process.env.NODE_ENV !== 'production'){
require('dotenv').config()
}
const port = process.env.PORT || 3000
const app = express();
const server = http.createServer(app)
const { initSocketIO } = require('./server/helpers/socket')
// Create a session
const newSession = session({
secret: 'combinify-secret',
resave: true,
saveUninitialized: true,
cookie: {
secure: 'auto',
},
})
// Require the routes
const home = require('./server/routes/home')
const login = require('./server/routes/login')
const callback = require('./server/routes/callback')
const create = require('./server/routes/create')
const playlists = require('./server/routes/playlists')
const error = require('./server/routes/error')
const offline = require('./server/routes/offline')
// Assign handlebars as the view engine
app.set('view engine', 'hbs');
app.set('views', __dirname + '/server/views')
app.engine('hbs', handlebars({
extname: 'hbs',
defaultLayout: 'main',
helpers: require('./server/config/handlebarsHelpers')
}))
app.set('trust proxy', 1)
app.use(express.static(__dirname + '/public'))
.use(compression())
.use(cors())
.use(cookieParser())
.use(express.json())
.use(express.urlencoded({ extended: true }))
.use(newSession)
.use('/', login)
.use('/home', home)
.use('/callback', callback)
.use('/create', create)
.use('/playlists', playlists)
.use('/offline', offline)
.use('/*', error)
// Initialize Socket.io
initSocketIO(server, newSession)
server.listen(port, () => {
console.log(`Listening on ${port}`)
})