From 6c2b72dd276b4a368ff0b0c826ac9c329c69f837 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Wed, 3 Jun 2020 17:05:36 +0100 Subject: [PATCH] logic to not use builder:token for apps running in dev --- packages/builder/src/builderStore/api.js | 11 ++++---- .../components/start/CreateAppModal.svelte | 11 ++------ .../src/pages/[application]/_reset.svelte | 3 ++- packages/builder/src/pages/index.svelte | 4 +-- .../server/src/middleware/authenticated.js | 25 +++++++++++++------ 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/packages/builder/src/builderStore/api.js b/packages/builder/src/builderStore/api.js index 04dcce6cb9..c132b01fc0 100644 --- a/packages/builder/src/builderStore/api.js +++ b/packages/builder/src/builderStore/api.js @@ -3,6 +3,7 @@ const apiCall = method => async (url, body) => { method: method, headers: { "Content-Type": "application/json", + "User-Agent": "Budibase Builder", }, body: body && JSON.stringify(body), }) @@ -14,11 +15,11 @@ const apiCall = method => async (url, body) => { return response } -const post = apiCall("POST") -const get = apiCall("GET") -const patch = apiCall("PATCH") -const del = apiCall("DELETE") -const put = apiCall("PUT") +export const post = apiCall("POST") +export const get = apiCall("GET") +export const patch = apiCall("PATCH") +export const del = apiCall("DELETE") +export const put = apiCall("PUT") export default { post, diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index d2232f7604..f012860194 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -5,6 +5,7 @@ import { AppsIcon, InfoIcon, CloseIcon } from "components/common/Icons/" import { getContext } from "svelte" import { fade } from "svelte/transition" + import { post } from "builderStore/api" const { open, close } = getContext("simple-modal") @@ -33,15 +34,7 @@ const data = { name, description } loading = true try { - const response = await fetch("/api/applications", { - method: "POST", // *GET, POST, PUT, DELETE, etc. - credentials: "same-origin", // include, *same-origin, omit - headers: { - "Content-Type": "application/json", - // 'Content-Type': 'application/x-www-form-urlencoded', - }, - body: JSON.stringify(data), // body data type must match "Content-Type" header - }) + const response = await post("/api/applications", data) const res = await response.json() diff --git a/packages/builder/src/pages/[application]/_reset.svelte b/packages/builder/src/pages/[application]/_reset.svelte index d973ba7517..2eec749c8f 100644 --- a/packages/builder/src/pages/[application]/_reset.svelte +++ b/packages/builder/src/pages/[application]/_reset.svelte @@ -1,6 +1,7 @@