✏️ Fix async data gathering with Dockerode

This commit is contained in:
ajnart
2022-07-22 16:19:28 +02:00
parent 3b0658fee2
commit a9b840452e

View File

@@ -21,37 +21,31 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
} }
// Get the container with the ID // Get the container with the ID
const container = docker.getContainer(id); const container = docker.getContainer(id);
// Get the container info const startAction = async () => {
container.inspect((err, data) => {
if (err) {
res.status(500).json({
message: err,
});
}
});
try {
switch (action) { switch (action) {
case 'remove': case 'remove':
await container.remove(); return container.remove();
break;
case 'start': case 'start':
container.start(); return container.start();
break;
case 'stop': case 'stop':
container.stop(); return container.stop();
break;
case 'restart': case 'restart':
container.restart(); return container.restart();
break; default:
return Promise;
} }
} catch (err) { };
res.status(500).json({ try {
message: err, await startAction();
return res.status(200).json({
statusCode: 200,
message: `Container ${id} ${action}ed`,
}); });
} catch (err) {
return res.status(500).json(
err,
);
} }
return res.status(200).json({
success: true,
});
} }
export default async (req: NextApiRequest, res: NextApiResponse) => { export default async (req: NextApiRequest, res: NextApiResponse) => {