arma-server-web-admin/app.js

68 lines
2.0 KiB
JavaScript
Raw Normal View History

var express = require('express');
var Resource = require('express-resource');
2014-02-09 03:19:48 +00:00
2014-04-04 08:37:43 +00:00
var config = require('./config');
var Manager = require('./lib/manager');
var Missions = require('./lib/missions');
var Mods = require('./lib/mods');
var Logs = require('./lib/logs');
2014-02-09 03:19:48 +00:00
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
2014-02-09 03:19:48 +00:00
if (config.auth && config.auth.username && config.auth.password) {
app.use(express.basicAuth(config.auth.username, config.auth.password));
}
2014-02-09 03:19:48 +00:00
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/public'));
var logs = new Logs(config);
var manager = new Manager(config, logs);
manager.load();
var missions = new Missions(config);
var mods = new Mods(config);
2015-02-14 18:42:18 +00:00
mods.updateMods();
var logsRoutes = require('./routes/logs')(logs);
2015-02-01 04:01:50 +00:00
var serversRoutes = require('./routes/servers')(manager, mods);
var missionsRoutes = require('./routes/missions')(missions);
2015-02-01 04:01:50 +00:00
var modsRoutes = require('./routes/mods')(mods);
2014-04-06 21:09:52 +00:00
app.resource('api/logs', logsRoutes);
app.resource('api/missions', missionsRoutes);
2015-02-01 04:01:50 +00:00
app.resource('api/mods', modsRoutes);
var serversResource = app.resource('api/servers', serversRoutes);
2014-04-04 08:37:43 +00:00
app.resource('api/settings', require('./routes/settings'));
2014-02-13 22:47:51 +00:00
2015-08-15 15:12:50 +00:00
app.post('/api/missions/workshop', require('./routes/workshop').mission);
2015-05-29 23:30:53 +00:00
app.post('/api/mods/refresh', modsRoutes.refresh);
2015-02-01 04:01:50 +00:00
app.post('/api/mods/search', modsRoutes.search);
app.get('/api/servers/:server/start', serversRoutes.start);
app.get('/api/servers/:server/stop', serversRoutes.stop);
2014-02-09 03:19:48 +00:00
2014-04-04 08:37:43 +00:00
app.get('/', function (req, res){
2014-02-09 03:19:48 +00:00
res.sendfile(__dirname + '/public/index.html');
});
io.on('connection', function (socket) {
socket.emit('mods', mods.mods);
socket.emit('servers', manager.getServers());
});
mods.on('mods', function(mods) {
io.emit('mods', mods);
});
manager.on('servers', function() {
io.emit('servers', manager.getServers());
});
server.listen(config.port,config.host);