2017-04-01 09:19:30 +00:00
|
|
|
var express = require('express');
|
|
|
|
|
2015-02-01 01:43:52 +00:00
|
|
|
module.exports = function (manager, mods) {
|
2017-04-01 09:19:30 +00:00
|
|
|
var router = express.Router();
|
|
|
|
|
|
|
|
router.get('/', function (req, res) {
|
|
|
|
res.json(manager.getServers());
|
|
|
|
});
|
|
|
|
|
|
|
|
router.post('/', function (req, res) {
|
|
|
|
var server = manager.addServer(req.body);
|
|
|
|
res.json(server);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/:server', function (req, res) {
|
|
|
|
var server = manager.getServer(req.params.server);
|
|
|
|
res.json(server);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.put('/:server', function (req, res) {
|
|
|
|
var server = manager.getServer(req.params.server);
|
|
|
|
server.update(req.body);
|
|
|
|
manager.save();
|
|
|
|
res.json(server);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.delete('/:server', function (req, res) {
|
|
|
|
var server = manager.removeServer(req.params.server);
|
|
|
|
res.json(server);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.post('/:server/start', function (req, res) {
|
|
|
|
var server = manager.getServer(req.params.server);
|
|
|
|
server.start();
|
|
|
|
res.json({status:"ok", pid: server.pid});
|
|
|
|
});
|
|
|
|
|
|
|
|
router.post('/:server/stop', function (req, res) {
|
|
|
|
var server = manager.getServer(req.params.server);
|
|
|
|
server.stop(function () {
|
|
|
|
if (!server.pid) {
|
|
|
|
res.json({status: true, pid: server.pid});
|
|
|
|
} else {
|
|
|
|
res.json({status: false, pid: server.pid});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return router;
|
2014-04-06 21:09:52 +00:00
|
|
|
};
|