-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (36 loc) · 1.1 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
42
require('dotenv').config()
const fs = require('fs')
const morgan = require('morgan')
const path = require('path')
const express = require('express')
const app = express()
const http = require('http')
const server = http.Server(app)
const io = require('socket.io')(server)
const manager = require('./game-manager.js')
const port = process.env.PORT || 3000
const clientDependencyMap = {
'/vue': 'node_modules/vue/dist',
'/nipplejs': 'node_modules/nipplejs/dist',
'/gl-matrix': 'node_modules/gl-matrix'
}
// create a write stream (in append mode)
const accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'), { flags: 'a' })
// setup the logger
app.use(morgan(
'combined',
{ stream: accessLogStream }
))
app.use('/', express.static('public'))
Object.keys(clientDependencyMap).forEach((key) => {
app.use(key, express.static(path.join(__dirname, clientDependencyMap[key])))
})
app.get('/data', function (request, response) {
response.json({
isOkay: true,
cats: false
})
})
manager.connectWebSockets(io)
server.listen(port)
console.log(`Starting up server at: http://localhost:${port}/`)