DockerRestApi/routes/status.js

29 lines
583 B
JavaScript
Raw Permalink Normal View History

2019-09-19 18:13:08 +00:00
var express = require('express');
var router = express.Router();
var docker = require('../bin/dockerode');
2019-09-19 16:07:12 +00:00
2019-09-19 18:13:08 +00:00
router.get('/:id', (req, res, next) => {
2019-09-19 18:23:48 +00:00
if (req.params.id.startsWith("mc") == true) {
getContainer(req.params.id).then(data => {
res.send(data);
});
}
else {
res.send("not whitelisted");
}
2019-09-19 16:07:12 +00:00
});
2019-09-19 18:13:08 +00:00
function getContainer(containername) {
return new Promise((resolve, reject) => {
const container = docker.getContainer(containername);
container.inspect((err, data) => {
resolve({ err, data });
});
})
}
module.exports = router;