-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 1.11 KB
/
index.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
const express = require('express')
const app = express()
const http = require('http').createServer(app)
const io = require('socket.io')(http)
const bodyParser = require('body-parser')
const database = require('./app/config/dbconfig')
const port = process.argv[2] || 3000
process.env = {
DEBUG: 'socket.io:client*'
}
process.on('exit', function (code) {
return console.log(`About to exit with code ${code}`)
})
database
.init
.then((db) => {
http.listen(port, function (err) {
if (err) {
console.error(err)
}
console.log('Server listening on port : ' + port)
})
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
/* Router configuration */
const REST_API_ROOT = '/api'
app.use(REST_API_ROOT, require('./app/routes/router'))
// accès aux pages statiques
app.use('/static', express.static('static'))
require('./app/handlers/index')(io) // on charge les handlers de socketio
})
// Middleware qui permet d'accéder à l'instance de socket io dans les handler d'express
app.use(function (_, res, next) {
res.io = io
next()
})