diff --git a/app.js b/app.js index 7e633fe..223cabb 100644 --- a/app.js +++ b/app.js @@ -5,7 +5,7 @@ var logger = require('morgan'); var statusRouter = require('./routes/status'); var startRouter = require('./routes/start'); -var stopRouter = require('./routes/stop'); + var app = express(); @@ -17,6 +17,6 @@ app.use(express.static(path.join(__dirname, 'public'))); app.use('/status', statusRouter); app.use('/start', startRouter); -app.use('/stop', stopRouter); + module.exports = app; diff --git a/bin/dockerode.js b/bin/dockerode.js index 6bb8c8b..f1a63fe 100644 --- a/bin/dockerode.js +++ b/bin/dockerode.js @@ -1,4 +1,7 @@ var Docker = require('dockerode'); var docker = new Docker({ socketPath: '/var/run/docker.sock' }); -module.exports = docker; \ No newline at end of file +module.exports = docker; + + + diff --git a/routes/start.js b/routes/start.js index 92e482b..a0c3f30 100644 --- a/routes/start.js +++ b/routes/start.js @@ -3,16 +3,22 @@ var router = express.Router(); var docker = require('../bin/dockerode'); -router.get('/', function (req, res, next) { - res.send(getContainer('Portainer')); +router.get('/:id', (req, res, next) => { + getContainer(id).then(data => { + res.send(data); + }); }); -module.exports = router; function getContainer(containername) { - var container = docker.getContainer(containername); - container.inspect(function (err, data) { - return data - }); -} \ No newline at end of file + return new Promise((resolve, reject) => { + const container = docker.getContainer(containername); + container.inspect((err, data) => { + resolve({ err, data }); + }); + }) +} + + +module.exports = router; \ No newline at end of file diff --git a/routes/status.js b/routes/status.js index 6561e07..a0c3f30 100644 --- a/routes/status.js +++ b/routes/status.js @@ -1,10 +1,24 @@ -var express = require('express'), - router = express.Router(); +var express = require('express'); +var router = express.Router(); +var docker = require('../bin/dockerode'); -router.get('/', function (req, res, next) { - res.send("body"); +router.get('/:id', (req, res, next) => { + getContainer(id).then(data => { + res.send(data); + }); }); -module.exports = router; + +function getContainer(containername) { + return new Promise((resolve, reject) => { + const container = docker.getContainer(containername); + container.inspect((err, data) => { + resolve({ err, data }); + }); + }) +} + + +module.exports = router; \ No newline at end of file diff --git a/routes/stop.js b/routes/stop.js deleted file mode 100644 index ac4689a..0000000 --- a/routes/stop.js +++ /dev/null @@ -1,9 +0,0 @@ -var express = require('express'); -var router = express.Router(); - -/* GET users listing. */ -router.get('/', function (req, res, next) { - res.send('respond with a resource'); -}); - -module.exports = router;