-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (43 loc) · 1.32 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
const express = require('express')
const server = express()
const http = require('http').Server(server)
const path = require('path')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const uuid = require('node-uuid')
const env = require('./config.json')
const router = require('./src/routes')
const chatServer = require('./lib/chatServer')
const session = require('express-session')({
uniqID: uuid.v4(),
secret: env.SECRET,
resave: true,
saveUninitialized: true,
cookie: {maxAge: 1.728e+8}
})
server.use(bodyParser.json(''))
server.use(bodyParser.urlencoded({extended: true}))
server.use(express.static(path.join(__dirname, '/public')))
server.use(session)
server.use(router)
// Database connection
mongoose.connect(`mongodb://${env.HOST_NAME}:${env.PORT_NUMBER}/${env.DB_NAME}`)
const db = mongoose.connection
db.on('something', (err) => console.log('Error occured', err))
db.once('open', (err) => {
if (err) {
throw new Error('DB not connected')
}
http.listen(process.env.PORT || 3000)
console.log('DB connected successfully at:', Date())
})
server.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public/app.html'))
})
server.get('/signin', (req, res) => {
res.redirect('/')
})
server.get('/signup', (req, res) => {
res.redirect('/home')
})
chatServer.listen(http, session)