2014-04-04 08:37:43 +00:00
|
|
|
var slug = require('slug');
|
|
|
|
|
|
|
|
var Manager = require('./../manager');
|
|
|
|
|
|
|
|
var manager = new Manager();
|
|
|
|
|
|
|
|
exports.index = function (req, res){
|
2014-04-06 22:58:17 +00:00
|
|
|
var servers = [];
|
|
|
|
|
|
|
|
manager.getServers().forEach(function (server) {
|
|
|
|
servers.push({
|
|
|
|
id: server.id,
|
|
|
|
title: server.title,
|
|
|
|
port: server.port,
|
|
|
|
mods: server.mods,
|
2014-04-08 22:08:36 +00:00
|
|
|
pid: server.pid,
|
|
|
|
});
|
2014-04-06 22:58:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
res.send(servers);
|
2014-04-04 08:37:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.create = function (req, res){
|
|
|
|
var title = req.body.title;
|
|
|
|
var id = slug(title);
|
|
|
|
res.send(manager.addServer(id, title));
|
|
|
|
};
|
|
|
|
|
2014-04-06 21:09:52 +00:00
|
|
|
exports.show = function (req, res){
|
2014-04-08 22:08:36 +00:00
|
|
|
var server = manager.getServer(req.params.server)
|
|
|
|
res.send({
|
|
|
|
id: server.id,
|
|
|
|
title: server.title,
|
|
|
|
port: server.port,
|
|
|
|
mods: server.mods,
|
|
|
|
pid: server.pid,
|
|
|
|
});
|
2014-04-06 21:09:52 +00:00
|
|
|
};
|
|
|
|
|
2014-04-04 08:37:43 +00:00
|
|
|
exports.update = function(req, res){
|
2014-04-08 20:59:59 +00:00
|
|
|
var server = manager.getServer(req.params.server);
|
|
|
|
|
|
|
|
if (req.body.mods) {
|
|
|
|
server.mods = req.body.mods;
|
|
|
|
}
|
|
|
|
|
|
|
|
manager.save();
|
|
|
|
|
|
|
|
res.send(server);
|
2014-04-04 08:37:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.destroy = function(req, res){
|
|
|
|
res.send('destroy server ' + req.params.server);
|
|
|
|
};
|
2014-04-06 21:09:52 +00:00
|
|
|
|
|
|
|
exports.start = function (req, res){
|
|
|
|
var server = manager.getServer(req.params.server);
|
|
|
|
server.start();
|
2014-04-06 22:58:17 +00:00
|
|
|
res.send({status:"ok", pid: server.pid});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.stop = function (req, res){
|
|
|
|
var server = manager.getServer(req.params.server);
|
|
|
|
server.stop(function () {
|
|
|
|
if (!server.pid) {
|
|
|
|
res.send({status: true, pid: server.pid});
|
|
|
|
} else {
|
|
|
|
res.send({status: false, pid: server.pid});
|
|
|
|
}
|
|
|
|
});
|
2014-04-06 21:09:52 +00:00
|
|
|
};
|