2014-06-04 22:19:54 +00:00
|
|
|
var express = require('express');
|
2017-04-01 09:19:30 +00:00
|
|
|
var basicAuth = require('express-basic-auth')
|
|
|
|
var bodyParser = require('body-parser');
|
|
|
|
var morgan = require('morgan');
|
|
|
|
var path = require('path');
|
|
|
|
var serveStatic = require('serve-static')
|
2014-02-09 03:19:48 +00:00
|
|
|
|
2014-04-04 08:37:43 +00:00
|
|
|
var config = require('./config');
|
2015-01-21 02:18:45 +00:00
|
|
|
var Manager = require('./lib/manager');
|
2016-10-29 14:34:54 +00:00
|
|
|
var Missions = require('./lib/missions');
|
2015-01-21 03:00:09 +00:00
|
|
|
var Mods = require('./lib/mods');
|
2015-10-31 14:27:16 +00:00
|
|
|
var Logs = require('./lib/logs');
|
2014-02-09 03:19:48 +00:00
|
|
|
|
|
|
|
var app = express();
|
2014-06-04 22:19:54 +00:00
|
|
|
var server = require('http').Server(app);
|
|
|
|
var io = require('socket.io')(server);
|
2014-02-09 03:19:48 +00:00
|
|
|
|
2015-05-30 00:29:48 +00:00
|
|
|
if (config.auth && config.auth.username && config.auth.password) {
|
2017-04-01 09:19:30 +00:00
|
|
|
var basicAuthUsers = {}
|
|
|
|
basicAuthUsers[config.auth.username] = config.auth.password;
|
|
|
|
app.use(basicAuth({
|
|
|
|
challenge: true,
|
|
|
|
users: basicAuthUsers
|
|
|
|
}));
|
2015-05-30 00:29:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-01 09:19:30 +00:00
|
|
|
app.use(bodyParser.json());
|
2017-04-01 11:18:11 +00:00
|
|
|
app.use(bodyParser.urlencoded({ extended: false }));
|
2017-04-01 09:19:30 +00:00
|
|
|
app.use(morgan('dev'));
|
|
|
|
app.use(serveStatic(path.join(__dirname, 'public')));
|
2014-02-09 03:19:48 +00:00
|
|
|
|
2015-10-31 14:27:16 +00:00
|
|
|
var logs = new Logs(config);
|
|
|
|
|
|
|
|
var manager = new Manager(config, logs);
|
2015-01-21 02:18:45 +00:00
|
|
|
manager.load();
|
2015-10-31 14:27:16 +00:00
|
|
|
|
2016-10-29 14:34:54 +00:00
|
|
|
var missions = new Missions(config);
|
2015-01-21 03:00:09 +00:00
|
|
|
var mods = new Mods(config);
|
2015-02-14 18:42:18 +00:00
|
|
|
mods.updateMods();
|
2015-01-21 03:00:09 +00:00
|
|
|
|
2017-04-01 09:19:30 +00:00
|
|
|
app.use('/api/logs', require('./routes/logs')(logs));
|
|
|
|
app.use('/api/missions', require('./routes/missions')(missions));
|
|
|
|
app.use('/api/mods', require('./routes/mods')(mods));
|
|
|
|
app.use('/api/servers', require('./routes/servers')(manager, mods));
|
|
|
|
app.use('/api/settings', require('./routes/settings')(config));
|
2014-02-09 03:19:48 +00:00
|
|
|
|
2014-06-04 22:19:54 +00:00
|
|
|
io.on('connection', function (socket) {
|
2015-02-01 04:27:12 +00:00
|
|
|
socket.emit('mods', mods.mods);
|
2014-06-04 22:19:54 +00:00
|
|
|
socket.emit('servers', manager.getServers());
|
|
|
|
});
|
|
|
|
|
2015-02-01 04:27:12 +00:00
|
|
|
mods.on('mods', function(mods) {
|
|
|
|
io.emit('mods', mods);
|
|
|
|
});
|
|
|
|
|
2014-06-04 22:19:54 +00:00
|
|
|
manager.on('servers', function() {
|
|
|
|
io.emit('servers', manager.getServers());
|
|
|
|
});
|
|
|
|
|
2015-05-29 15:23:19 +00:00
|
|
|
server.listen(config.port,config.host);
|