arma-server-web-admin/app.js

55 lines
1.5 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 Mods = require('./lib/mods');
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
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/public'));
var manager = new Manager(config);
manager.load();
var mods = new Mods(config);
2015-02-14 18:42:18 +00:00
mods.updateMods();
2015-02-01 04:01:50 +00:00
var serversRoutes = require('./routes/servers')(manager, mods);
var modsRoutes = require('./routes/mods')(mods);
2014-04-06 21:09:52 +00:00
app.resource('api/logs', require('./routes/logs'));
2014-04-04 08:37:43 +00:00
app.resource('api/missions', require('./routes/missions'));
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-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);