2014-06-04 22:19:54 +00:00
|
|
|
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');
|
2014-06-04 22:19:54 +00:00
|
|
|
var manager = require('./manager');
|
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
|
|
|
|
|
|
|
app.use(express.logger('dev'));
|
|
|
|
app.use(express.cookieParser());
|
|
|
|
app.use(express.bodyParser());
|
|
|
|
app.use(express.methodOverride());
|
|
|
|
app.use(express.static(__dirname + '/public'));
|
|
|
|
|
2014-04-06 21:09:52 +00:00
|
|
|
var servers = require('./routes/servers');
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2014-06-04 22:19:54 +00:00
|
|
|
io.on('connection', function (socket) {
|
|
|
|
socket.emit('servers', manager.getServers());
|
|
|
|
});
|
|
|
|
|
|
|
|
manager.on('servers', function() {
|
|
|
|
io.emit('servers', manager.getServers());
|
|
|
|
});
|
|
|
|
|
|
|
|
server.listen(3000);
|