arma-server-web-admin/main.js

68 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-02-09 03:19:48 +00:00
var express = require('express'),
2014-02-13 22:47:51 +00:00
fs = require('fs'),
slug = require('slug');
2014-02-09 03:19:48 +00:00
var config = require('./config'),
2014-02-14 00:13:11 +00:00
Manager = require('./manager');
2014-02-09 03:19:48 +00:00
var app = express();
2014-02-13 22:47:51 +00:00
var manager = new Manager();
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'));
app.get('/api/missions', function (req, res){
var path = config.path + '/mpmissions';
fs.readdir(path, function (err, files) {
if (err) {
res.send(err);
} else {
res.send(files);
}
});
});
app.get('/api/mods', function (req, res){
fs.readdir(config.path, function (err, files) {
if (err) {
res.send(err);
} else {
var mods = files.filter(function (file) {
return file.charAt(0) == "@";
}).map(function (mod) {
return { name: mod }
});
res.send(mods);
}
});
});
app.get('/api/servers', function (req, res){
2014-02-13 22:47:51 +00:00
res.send(manager.servers);
});
app.post('/api/servers', function (req, res){
var title = req.body.title;
var id = slug(title);
manager.addServer(id, title);
res.send(manager.servers);
});
app.get('/api/servers/:id/start', function (req, res){
manager.runServer();
res.send({status:"ok"});
2014-02-09 03:19:48 +00:00
});
app.get('/api/settings', function (req, res){
res.send(config);
});
app.get('/*', function (req, res){
res.sendfile(__dirname + '/public/index.html');
});
app.listen(3000);