From 71af662998db1c9c2afa944b9227942033e54bfc Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Tue, 14 Jan 2025 23:18:38 +0800 Subject: [PATCH] fix: addressed cloudflare pages error 304 --- .../integration-sync-secret.ts | 33 +++++++++++-------- .../CloudflarePagesConfigurePage.tsx | 20 ++++++----- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/backend/src/services/integration-auth/integration-sync-secret.ts b/backend/src/services/integration-auth/integration-sync-secret.ts index 9ddd1e789..5c66a1012 100644 --- a/backend/src/services/integration-auth/integration-sync-secret.ts +++ b/backend/src/services/integration-auth/integration-sync-secret.ts @@ -3711,11 +3711,10 @@ const syncSecretsCloudflarePages = async ({ const getSecretsRes = ( await request.get<{ result: { deployment_configs: Record }> }; - }>(`${IntegrationUrls.CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}?_=${Date.now()}`, { + }>(`${IntegrationUrls.CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`, { headers: { Authorization: `Bearer ${accessToken}`, - Accept: "application/json", - "Cache-Control": "no-store" + Accept: "application/json" } }) ).data.result.deployment_configs[integration.targetEnvironment as string].env_vars; @@ -3751,17 +3750,25 @@ const syncSecretsCloudflarePages = async ({ ); const metadata = z.record(z.any()).parse(integration.metadata); - if (metadata.shouldAutoRedeploy) { - await request.post( - `${IntegrationUrls.CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}/deployments`, - {}, - { - headers: { - Authorization: `Bearer ${accessToken}`, - Accept: "application/json" + if (metadata.shouldAutoRedeploy && integration.targetEnvironment === "production") { + await request + .post( + `${IntegrationUrls.CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}/deployments`, + {}, + { + headers: { + Authorization: `Bearer ${accessToken}`, + Accept: "application/json" + } } - } - ); + ) + .catch((error) => { + if (error instanceof AxiosError && error.response?.status === 304) { + return; + } + + throw error; + }); } }; diff --git a/frontend/src/pages/secret-manager/integrations/CloudflarePagesConfigurePage/CloudflarePagesConfigurePage.tsx b/frontend/src/pages/secret-manager/integrations/CloudflarePagesConfigurePage/CloudflarePagesConfigurePage.tsx index 1101d8081..03be1dab6 100644 --- a/frontend/src/pages/secret-manager/integrations/CloudflarePagesConfigurePage/CloudflarePagesConfigurePage.tsx +++ b/frontend/src/pages/secret-manager/integrations/CloudflarePagesConfigurePage/CloudflarePagesConfigurePage.tsx @@ -192,15 +192,17 @@ export const CloudflarePagesConfigurePage = () => { ))} -
- setShouldAutoRedeploy(isChecked)} - isChecked={shouldAutoRedeploy} - > - Auto-redeploy service upon secret change - -
+ {targetEnvironment === "production" && ( +
+ setShouldAutoRedeploy(isChecked)} + isChecked={shouldAutoRedeploy} + > + Auto-redeploy service upon secret change + +
+ )}