From c4b93b5288a90612bcf4b95b0744cbe7cc380582 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Sep 2025 13:56:36 +0000 Subject: [PATCH] Update --- backend/index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/index.js b/backend/index.js index ede24fc..dcc837e 100644 --- a/backend/index.js +++ b/backend/index.js @@ -27,6 +27,9 @@ app.get('*', (req, res, next) => { // Backend-Port fix const PORT = 4001; +// Endpoint-ID aus der env +const ENDPOINT_ID = Number(process.env.PORTAINER_ENDPOINT_ID); + // HTTPS Agent für Self-Signed-Zertifikate const agent = new https.Agent({ rejectUnauthorized: false }); @@ -57,19 +60,24 @@ const broadcastRedeployStatus = (stackId, status) => { app.get('/api/stacks', async (req, res) => { try { const stacksRes = await axiosInstance.get('/api/stacks'); + + // Filter nach Endpoint-ID + const filteredStacks = stacksRes.data.filter(stack => stack.EndpointId === ENDPOINT_ID); + const stacksWithStatus = await Promise.all( - stacksRes.data.map(async (stack) => { + filteredStacks.map(async (stack) => { try { const statusRes = await axiosInstance.get( `/api/stacks/${stack.Id}/images_status?refresh=true` ); - let statusEmoji = statusRes.data.Status === 'outdated' ? '⚠️' : '✅'; + const statusEmoji = statusRes.data.Status === 'outdated' ? '⚠️' : '✅'; return { ...stack, updateStatus: statusEmoji, redeploying: redeployingStacks[stack.Id] || false }; } catch { return { ...stack, updateStatus: '❌', redeploying: redeployingStacks[stack.Id] || false }; } }) ); + stacksWithStatus.sort((a, b) => a.Name.localeCompare(b.Name)); res.json(stacksWithStatus); } catch (err) { @@ -85,6 +93,11 @@ app.put('/api/stacks/:id/redeploy', async (req, res) => { const stackRes = await axiosInstance.get(`/api/stacks/${id}`); const stack = stackRes.data; + // Prüfen, ob Stack zum konfigurierten Endpoint gehört + if (stack.EndpointId !== ENDPOINT_ID) { + throw new Error(`Stack gehört nicht zum Endpoint ${ENDPOINT_ID}`); + } + if (stack.Type === 1) { await axiosInstance.put(`/api/stacks/${id}/git/redeploy?endpointId=${stack.EndpointId}`); } else if (stack.Type === 2) {