arma-server-web-admin/app.js
2015-01-21 04:00:09 +01:00

46 lines
1.3 KiB
JavaScript

var express = require('express');
var Resource = require('express-resource');
var config = require('./config');
var Manager = require('./lib/manager');
var Mods = require('./lib/mods');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
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);
var servers = require('./routes/servers')(manager);
app.resource('api/logs', require('./routes/logs'));
app.resource('api/missions', require('./routes/missions'));
app.resource('api/mods', require('./routes/mods')(mods));
var serversResource = app.resource('api/servers', servers);
app.resource('api/settings', require('./routes/settings'));
app.get('/api/servers/:server/start', servers.start);
app.get('/api/servers/:server/stop', servers.stop);
app.get('/', function (req, res){
res.sendfile(__dirname + '/public/index.html');
});
io.on('connection', function (socket) {
socket.emit('servers', manager.getServers());
});
manager.on('servers', function() {
io.emit('servers', manager.getServers());
});
server.listen(config.port);