implement start and status
This commit is contained in:
parent
6407ea4993
commit
b9ebac85c1
5 changed files with 39 additions and 25 deletions
4
app.js
4
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;
|
||||
|
|
|
@ -2,3 +2,6 @@ var Docker = require('dockerode');
|
|||
var docker = new Docker({ socketPath: '/var/run/docker.sock' });
|
||||
|
||||
module.exports = docker;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
return new Promise((resolve, reject) => {
|
||||
const container = docker.getContainer(containername);
|
||||
container.inspect((err, data) => {
|
||||
resolve({ err, data });
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
module.exports = router;
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function getContainer(containername) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const container = docker.getContainer(containername);
|
||||
container.inspect((err, data) => {
|
||||
resolve({ err, data });
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
module.exports = router;
|
|
@ -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;
|
Loading…
Reference in a new issue