Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
60 lines (47 loc) · 1.54 KB
/
Copy pathapp.js
File metadata and controls
60 lines (47 loc) · 1.54 KB
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
require('dotenv').config()
if (process.env.NEW_RELIC_LICENSE_KEY && process.env.NEW_RELIC_APP_NAME) {
require('newrelic')
}
const bodyParser = require('body-parser')
const express = require('express')
const favicon = require('serve-favicon')
const http = require('http')
const logger = require('morgan')
const path = require('path')
const SocketIO = require('socket.io').Server
const State = require('./lib/State')
const Arma3Sync = require('./lib/Arma3Sync')
const FileHashCache = require('./lib/FileHashCache')
const Mods = require('./lib/Mods')
const app = express()
const server = http.Server(app)
const io = new SocketIO(server)
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(logger('dev'))
app.use(require('connect-livereload')())
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
app.use(express.static(path.join(__dirname, 'public')))
const state = new State()
const fileHashCache = new FileHashCache(
process.env.ARMA3SYNC_REPO_PATH,
process.env.FILE_HASH_CACHE || 'hash-cache.json'
)
const arma3sync = new Arma3Sync(state, fileHashCache)
const mods = new Mods(state, arma3sync)
app.use('/api', require('./api')(arma3sync, mods))
app.get('/*', (req, res) => {
res.render('public/index.html')
})
io.on('connection', (socket) => {
socket.emit('mods', mods.mods)
socket.emit('state', state.state)
})
mods.on('mods', (mods) => {
io.emit('mods', mods)
})
state.on('state', (state) => {
io.emit('state', state)
})
arma3sync.validate()
server.listen(process.env.WEB_PORT, process.env.WEB_HOST)