From 21a9840b8b36655985a7ea02f4ffdf011d049c8b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 19 Nov 2020 20:04:30 +0000 Subject: [PATCH] Add header to flag whether a request originates from the client --- .../userInterface/AppPreview/iframeTemplate.js | 2 +- packages/client/src/api/api.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/userInterface/AppPreview/iframeTemplate.js b/packages/builder/src/components/userInterface/AppPreview/iframeTemplate.js index 7b4e0d6b33..745ae7c89b 100644 --- a/packages/builder/src/components/userInterface/AppPreview/iframeTemplate.js +++ b/packages/builder/src/components/userInterface/AppPreview/iframeTemplate.js @@ -53,7 +53,7 @@ export default ` document.head.appendChild(styles) styles.appendChild(document.createTextNode(data.styles)) - window["##BUDIBASE_FRONTEND_DEFINITION##"] = data.frontendDefinition; + window["##BUDIBASE_IN_BUILDER##"] = true; if (window.loadBudibase) { loadBudibase() } diff --git a/packages/client/src/api/api.js b/packages/client/src/api/api.js index 998d123f14..e338b42b9c 100644 --- a/packages/client/src/api/api.js +++ b/packages/client/src/api/api.js @@ -26,13 +26,17 @@ const handleError = error => { const makeApiCall = async ({ method, url, body, json = true }) => { try { const requestBody = json ? JSON.stringify(body) : body + let headers = { + Accept: "application/json", + "Content-Type": "application/json", + "x-budibase-app-id": getAppId(), + } + if (!window["##BUDIBASE_IN_BUILDER##"]) { + headers["x-budibase-type"] = "client" + } const response = await fetch(url, { method, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "x-budibase-app-id": getAppId(), - }, + headers, body: requestBody, credentials: "same-origin", })