Add header to flag whether a request originates from the client

This commit is contained in:
Andrew Kingston 2020-11-19 20:04:30 +00:00
parent 674b89df5d
commit 2cb4cb2ce9
2 changed files with 10 additions and 6 deletions

View File

@ -53,7 +53,7 @@ export default `<html>
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()
}

View File

@ -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",
})