mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 07:55:52 +01:00
✏️ Fix async data gathering with Dockerode
This commit is contained in:
@@ -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({
|
|
||||||
message: err,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
await startAction();
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
statusCode: 200,
|
||||||
|
message: `Container ${id} ${action}ed`,
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(500).json(
|
||||||
|
err,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user