-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·49 lines (34 loc) · 1.48 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
//MARK: -------- MODULES & GLOBALS
const port = 9000
const bodyParser = require('body-parser')
const express = require('express')
const expressApp = express()
const http = require('http').Server(expressApp)
const sequelizeWrapper = require('./db/sequelizeWrapper')()
const messagesDBHelper = require('./db/messagesDBHelper')(sequelizeWrapper)
const socketIOConfig = require('./socketIO/socketIOConfig')(http)
const chatSocketHandler = require('./socketIO/chatSocketHandler')(messagesDBHelper)
const chatMessengerRouteMethods = require('./chatMessengerAPI/chatMessengerRouteMethods')(messagesDBHelper)
const chatMessengerRouter = require('./chatMessengerAPI/chatMessengerRouter')(express.Router(), chatMessengerRouteMethods)
//MARK: -------- MODULES & GLOBALS
//MARK: -------- INITIALISATION
expressApp.use(bodyParser.json())
http.listen(port, () => {
console.log(`listening on port: ${port}`)
})
//MARK: -------- INITIALISATION
//MARK: -------- ROUTES & SOCKET CONNECTIONS
expressApp.use('/api/messages/', chatMessengerRouter)
//establish socket connection and then begin listening for, emitting and saving chat messages
socketIOConfig.initConnection(chatSocketHandler.initChatConnection, onError)
//MARK: -------- ROUTES & SOCKET CONNECTIONS
//MARK: --------- ERROR HANDLING
/**
* Called to handle errors from socketIO
*
* @param error - the error specified by the promise which threw the error
*/
function onError(error){
console.log(`error is: ${error}`)
}
//MARK: --------- ERROR HANDLING