add start/stop/restart feature on containers

This commit is contained in:
Thomas Camlong
2022-06-27 23:38:54 +02:00
parent 72aba9d8cd
commit 035224b02b
3 changed files with 93 additions and 41 deletions

View File

@@ -29,11 +29,39 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
});
}
});
if (action === 'restart') {
await container.restart();
return res.status(200).json({
success: true,
});
switch (action) {
case 'start':
container.start((err, data) => {
if (err) {
res.status(500).json({
message: err,
});
}
});
break;
case 'stop':
container.stop((err, data) => {
if (err) {
res.status(500).json({
message: err,
});
}
});
break;
case 'restart':
container.restart((err, data) => {
if (err) {
res.status(500).json({
message: err,
});
}
});
break;
default:
res.status(400).json({
message: 'Invalid action',
});
}
return res.status(200).json({
success: true,