arma-server-web-admin/app.js

43 lines
1.2 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');
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 servers = require('./routes/servers')(manager);
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'));
app.resource('api/mods', require('./routes/mods'));
2014-04-08 21:49:40 +00:00
var serversResource = app.resource('api/servers', servers);
2014-04-04 08:37:43 +00:00
app.resource('api/settings', require('./routes/settings'));
2014-02-13 22:47:51 +00:00
2014-04-06 21:09:52 +00:00
app.get('/api/servers/:server/start', servers.start);
2014-04-06 22:58:17 +00:00
app.get('/api/servers/:server/stop', servers.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('servers', manager.getServers());
});
manager.on('servers', function() {
io.emit('servers', manager.getServers());
});
2015-01-16 21:50:52 +00:00
server.listen(config.port);