Skip to content

Commit

Permalink
fix: change to asnync fonction
Browse files Browse the repository at this point in the history
  • Loading branch information
qfdk committed Feb 22, 2024
1 parent 7e95567 commit 60c1bee
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 590 deletions.
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const bodyParser = require('body-parser');
const app = express();
const session = require('express-session');

const {checkUser} = require('./middlewares/security');
const { checkUser } = require('./middlewares/security');

const io = require('socket.io')();
const favicon = require('serve-favicon');
Expand Down Expand Up @@ -35,7 +35,7 @@ app.use(session({
app.use('/static', express.static(__dirname + '/public'));
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

app.all('*', (req, res, next) => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"body-parser": "1.20.1",
"dockerode": "^4.0.0",
"dockerode": "^4.0.2",
"ejs": "^2.5.7",
"express": "^4.16.4",
"express-session": "^1.17.1",
Expand All @@ -16,6 +16,6 @@
"socket.io": "2.4.1"
},
"devDependencies": {
"nodemon": "^2.0.4"
"nodemon": "^3.0.3"
}
}
41 changes: 23 additions & 18 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ const Docker = require('dockerode');
const docker = new Docker();

/* GET overview. */
router.get('/overview', (req, res, next) => {
docker.info((err, info) => {
if (err) {
res.json({
msg: 'error',
message: 'Docker is running ?',
});
} else {
res.json(info);
}
});
router.get('/overview', async (req, res, next) => {
try {
const info = await docker.info();
return res.json(info);
} catch (err) {
res.json({
msg: 'error',
message: err.toString()
});
}
});

/**
* containers list
*/
router.get('/containers', (req, res, next) => {
docker.listContainers({all: true}, (err, containers) => {
res.json(containers);
});
router.get('/containers', async (req, res, next) => {
try {
const listContainers = await docker.listContainers({ all: true });
return res.json(listContainers);
} catch (err) {
res.json({
msg: 'error',
message: err.toString()
});
}
});

router.get('/containers/start/:id', (req, res, next) => {
Expand Down Expand Up @@ -62,7 +67,7 @@ router.get('/containers/stop/:id', (req, res, next) => {

router.get('/containers/remove/:id', (req, res, next) => {
const container = docker.getContainer(req.params.id);
container.remove({force: true}, (err, data) => {
container.remove({ force: true }, (err, data) => {
if (!err) {
res.json({
code: 200,
Expand Down Expand Up @@ -93,7 +98,7 @@ router.get('/images/remove/:id', (req, res, next) => {
imageId = imageId.split(':')[1];
}
const image = docker.getImage(imageId);
image.remove({force: true}, (err, data) => {
image.remove({ force: true }, (err, data) => {
if (err) {
res.json(err);
} else {
Expand All @@ -104,7 +109,7 @@ router.get('/images/remove/:id', (req, res, next) => {

router.get('/search/:name', (req, res, next) => {
const name = req.params.name;
docker.searchImages({term: name}, (err, data) => {
docker.searchImages({ term: name }, (err, data) => {
if (err) throw err;
res.json(data);
});
Expand Down
Loading

0 comments on commit 60c1bee

Please sign in to comment.