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