arma-server-web-admin/routes/servers.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

var express = require('express')
2017-04-01 09:19:30 +00:00
module.exports = function (manager, mods) {
var router = express.Router()
2017-04-01 09:19:30 +00:00
router.get('/', function (req, res) {
res.json(manager.getServers())
})
2017-04-01 09:19:30 +00:00
router.post('/', function (req, res) {
2021-02-28 14:26:26 +00:00
if (!req.body.title) {
res.status(400).send('Server title cannot be empty')
return
}
var server = manager.addServer(req.body)
res.json(server)
})
2017-04-01 09:19:30 +00:00
router.get('/:server', function (req, res) {
var server = manager.getServer(req.params.server)
res.json(server)
})
2017-04-01 09:19:30 +00:00
router.put('/:server', function (req, res) {
2021-02-28 14:26:26 +00:00
if (!req.body.title) {
res.status(400).send('Server title cannot be empty')
return
}
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) {
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) {
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-04-01 09:19:30 +00:00
router.post('/:server/stop', function (req, res) {
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-04-01 09:19:30 +00:00
return router
}