Bundle app ID inside apps, rather than trying to find it dynamically

This commit is contained in:
Andrew Kingston 2021-01-07 14:53:56 +00:00
parent 32c71bd006
commit cf087209d7
10 changed files with 16 additions and 13 deletions

View File

@ -30,6 +30,7 @@
} }
$: selectedComponentId = $store.selectedComponentId ?? "" $: selectedComponentId = $store.selectedComponentId ?? ""
$: previewData = { $: previewData = {
appId: $store.appId,
layout, layout,
screen, screen,
selectedComponentId, selectedComponentId,

View File

@ -22,10 +22,11 @@
} }
// Extract data from message // Extract data from message
const { selectedComponentId, layout, screen, previewType } = JSON.parse(event.data) const { selectedComponentId, layout, screen, previewType, appId } = JSON.parse(event.data)
// Set some flags so the app knows we're in the builder // Set some flags so the app knows we're in the builder
window["##BUDIBASE_IN_BUILDER##"] = true window["##BUDIBASE_IN_BUILDER##"] = true
window["##BUDIBASE_APP_ID##"] = appId
window["##BUDIBASE_PREVIEW_LAYOUT##"] = layout window["##BUDIBASE_PREVIEW_LAYOUT##"] = layout
window["##BUDIBASE_PREVIEW_SCREEN##"] = screen window["##BUDIBASE_PREVIEW_SCREEN##"] = screen
window["##BUDIBASE_SELECTED_COMPONENT_ID##"] = selectedComponentId window["##BUDIBASE_SELECTED_COMPONENT_ID##"] = selectedComponentId

View File

@ -1,5 +1,3 @@
import { getAppId } from "../utils/getAppId"
/** /**
* API cache for cached request responses. * API cache for cached request responses.
*/ */
@ -30,7 +28,7 @@ const makeApiCall = async ({ method, url, body, json = true }) => {
let headers = { let headers = {
Accept: "application/json", Accept: "application/json",
"Content-Type": "application/json", "Content-Type": "application/json",
"x-budibase-app-id": getAppId(), "x-budibase-app-id": window["##BUDIBASE_APP_ID##"],
} }
if (!window["##BUDIBASE_IN_BUILDER##"]) { if (!window["##BUDIBASE_IN_BUILDER##"]) {
headers["x-budibase-type"] = "client" headers["x-budibase-type"] = "client"

View File

@ -7,6 +7,7 @@ const loadBudibase = () => {
// Update builder store with any builder flags // Update builder store with any builder flags
builderStore.set({ builderStore.set({
inBuilder: !!window["##BUDIBASE_IN_BUILDER##"], inBuilder: !!window["##BUDIBASE_IN_BUILDER##"],
appId: window["##BUDIBASE_APP_ID##"],
layout: window["##BUDIBASE_PREVIEW_LAYOUT##"], layout: window["##BUDIBASE_PREVIEW_LAYOUT##"],
screen: window["##BUDIBASE_PREVIEW_SCREEN##"], screen: window["##BUDIBASE_PREVIEW_SCREEN##"],
selectedComponentId: window["##BUDIBASE_SELECTED_COMPONENT_ID##"], selectedComponentId: window["##BUDIBASE_SELECTED_COMPONENT_ID##"],

View File

@ -2,7 +2,6 @@ import * as API from "./api"
import { authStore, routeStore, screenStore, bindingStore } from "./store" import { authStore, routeStore, screenStore, bindingStore } from "./store"
import { styleable } from "./utils/styleable" import { styleable } from "./utils/styleable"
import { linkable } from "./utils/linkable" import { linkable } from "./utils/linkable"
import { getAppId } from "./utils/getAppId"
import DataProvider from "./components/DataProvider.svelte" import DataProvider from "./components/DataProvider.svelte"
export default { export default {
@ -12,7 +11,6 @@ export default {
screenStore, screenStore,
styleable, styleable,
linkable, linkable,
getAppId,
DataProvider, DataProvider,
setBindableValue: bindingStore.actions.setBindableValue, setBindableValue: bindingStore.actions.setBindableValue,
} }

View File

@ -1,8 +1,8 @@
import * as API from "../api" import * as API from "../api"
import { getAppId } from "../utils/getAppId" import { writable, get } from "svelte/store"
import { writable } from "svelte/store"
import { initialise } from "./initialise" import { initialise } from "./initialise"
import { routeStore } from "./routes" import { routeStore } from "./routes"
import { builderStore } from "./builder"
const createAuthStore = () => { const createAuthStore = () => {
const store = writable("") const store = writable("")
@ -25,7 +25,7 @@ const createAuthStore = () => {
} }
const logOut = async () => { const logOut = async () => {
store.set("") store.set("")
const appId = getAppId() const appId = get(builderStore).appId
if (appId) { if (appId) {
for (let environment of ["local", "cloud"]) { for (let environment of ["local", "cloud"]) {
window.document.cookie = `budibase:${appId}:${environment}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;` window.document.cookie = `budibase:${appId}:${environment}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`

View File

@ -3,6 +3,7 @@ import { writable } from "svelte/store"
const createBuilderStore = () => { const createBuilderStore = () => {
const initialState = { const initialState = {
inBuilder: false, inBuilder: false,
appId: null,
layout: null, layout: null,
screen: null, screen: null,
selectedComponentId: null, selectedComponentId: null,

View File

@ -1,8 +1,7 @@
import { writable, derived } from "svelte/store" import { writable, derived, get } from "svelte/store"
import { routeStore } from "./routes" import { routeStore } from "./routes"
import { builderStore } from "./builder" import { builderStore } from "./builder"
import * as API from "../api" import * as API from "../api"
import { getAppId } from "../utils/getAppId"
const createScreenStore = () => { const createScreenStore = () => {
const config = writable({ const config = writable({
@ -40,7 +39,7 @@ const createScreenStore = () => {
) )
const fetchScreens = async () => { const fetchScreens = async () => {
const appDefinition = await API.fetchAppDefinition(getAppId()) const appDefinition = await API.fetchAppDefinition(get(builderStore).appId)
config.set({ config.set({
screens: appDefinition.screens, screens: appDefinition.screens,
layouts: appDefinition.layouts, layouts: appDefinition.layouts,

View File

@ -168,6 +168,7 @@ exports.serveApp = async function(ctx) {
head, head,
body: html, body: html,
style: css.code, style: css.code,
appId: ctx.params.appId,
}) })
} }

View File

@ -5,6 +5,9 @@
{{{head}}} {{{head}}}
</head> </head>
{{{body}}} <script>
window["##BUDIBASE_APP_ID##"] = "{{appId}}"
</script>
{{{body}}}
</html> </html>