bugfixes... incorrect routing from builder to instances
This commit is contained in:
parent
d9aac103ee
commit
64ca63926f
|
@ -18,7 +18,12 @@ const _builderProxy = proxy("/_builder", {
|
||||||
})
|
})
|
||||||
|
|
||||||
const apiProxy = proxy(
|
const apiProxy = proxy(
|
||||||
["/_builder/assets/**", "/_builder/api/**", "/_builder/**/componentlibrary"],
|
[
|
||||||
|
"/_builder/assets/**",
|
||||||
|
"/_builder/api/**",
|
||||||
|
"/_builder/**/componentlibrary",
|
||||||
|
"/_builder/instance/**",
|
||||||
|
],
|
||||||
{
|
{
|
||||||
target,
|
target,
|
||||||
logLevel: "debug",
|
logLevel: "debug",
|
||||||
|
|
|
@ -32,3 +32,24 @@ export const makeLibraryUrl = (appName, lib) =>
|
||||||
|
|
||||||
export const libsFromPages = pages =>
|
export const libsFromPages = pages =>
|
||||||
pipe(pages, [values, map(p => p.componentLibraries), flatten, uniq])
|
pipe(pages, [values, map(p => p.componentLibraries), flatten, uniq])
|
||||||
|
|
||||||
|
export const libUrlsForPreview = (appPackage, pageName) => {
|
||||||
|
const resolve = path => {
|
||||||
|
let file = appPackage.components.libraryPaths[path]
|
||||||
|
if (file.startsWith("./")) file = file.substring(2)
|
||||||
|
if (file.startsWith("/")) file = file.substring(1)
|
||||||
|
|
||||||
|
let newPath = path
|
||||||
|
|
||||||
|
if (!newPath.startsWith("./") && !newPath.startsWith("/")) {
|
||||||
|
newPath = `/node_modules/${path}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
importPath: `/lib${newPath}/${file}`,
|
||||||
|
libName: path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pipe([appPackage.pages[pageName]], [libsFromPages, map(resolve)])
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import {
|
||||||
getBuiltin,
|
getBuiltin,
|
||||||
} from "../userInterface/pagesParsing/createProps"
|
} from "../userInterface/pagesParsing/createProps"
|
||||||
import { expandComponentDefinition } from "../userInterface/pagesParsing/types"
|
import { expandComponentDefinition } from "../userInterface/pagesParsing/types"
|
||||||
import { loadLibs, loadLibUrls } from "./loadComponentLibraries"
|
import { loadLibs, libUrlsForPreview } from "./loadComponentLibraries"
|
||||||
import { buildCodeForScreens } from "./buildCodeForScreens"
|
import { buildCodeForScreens } from "./buildCodeForScreens"
|
||||||
import { generate_screen_css } from "./generate_css"
|
import { generate_screen_css } from "./generate_css"
|
||||||
import { insertCodeMetadata } from "./insertCodeMetadata"
|
import { insertCodeMetadata } from "./insertCodeMetadata"
|
||||||
|
@ -153,9 +153,16 @@ const initialise = (store, initial) => async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
initial.libraries = await loadLibs(appname, pkg)
|
initial.libraries = await loadLibs(appname, pkg)
|
||||||
initial.loadLibraryUrls = () => loadLibUrls(appname, pkg)
|
initial.loadLibraryUrls = pageName => {
|
||||||
|
const libs = libUrlsForPreview(pkg, pageName)
|
||||||
|
return libs
|
||||||
|
}
|
||||||
initial.appname = appname
|
initial.appname = appname
|
||||||
initial.pages = pkg.pages
|
initial.pages = pkg.pages
|
||||||
|
initial.currentInstanceId =
|
||||||
|
pkg.application.instances && pkg.application.instances.length > 0
|
||||||
|
? pkg.application.instances[0].id
|
||||||
|
: ""
|
||||||
initial.hasAppPackage = true
|
initial.hasAppPackage = true
|
||||||
initial.hierarchy = pkg.appDefinition.hierarchy
|
initial.hierarchy = pkg.appDefinition.hierarchy
|
||||||
initial.accessLevels = pkg.accessLevels
|
initial.accessLevels = pkg.accessLevels
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
$: frontendDefinition = {
|
$: frontendDefinition = {
|
||||||
componentLibraries: $store.loadLibraryUrls(),
|
componentLibraries: $store.loadLibraryUrls($store.currentPageName),
|
||||||
page: $store.currentPreviewItem,
|
page: $store.currentPreviewItem,
|
||||||
screens: [{
|
screens: [{
|
||||||
name: "Screen Placeholder",
|
name: "Screen Placeholder",
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
appRootPath: "",
|
appRootPath: `/_builder/instance/${$store.appname}/${$store.currentInstanceId}/`,
|
||||||
}
|
}
|
||||||
|
|
||||||
$: backendDefinition = {
|
$: backendDefinition = {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
const { getAppRelativePath } = require("./helpers")
|
||||||
|
|
||||||
const send = require("koa-send")
|
const send = require("koa-send")
|
||||||
|
|
||||||
module.exports = async (ctx, next) => {
|
module.exports = async (ctx, next) => {
|
||||||
const path = ctx.path.replace(`/${ctx.params.appname}`, "")
|
const path = getAppRelativePath(ctx.params.appname, ctx.path)
|
||||||
|
|
||||||
if (path.startsWith("/api/")) {
|
if (path.startsWith("/api/")) {
|
||||||
await next()
|
await next()
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
exports.getRecordKey = (appname, wholePath) =>
|
exports.getRecordKey = (appname, wholePath) =>
|
||||||
wholePath
|
this.getAppRelativePath(appname, wholePath)
|
||||||
.replace(`/${appname}/api/files/`, "")
|
.replace(`/api/files/`, "/")
|
||||||
.replace(`/${appname}/api/lookup_field/`, "")
|
.replace(`/api/lookup_field/`, "/")
|
||||||
.replace(`/${appname}/api/record/`, "")
|
.replace(`/api/record/`, "/")
|
||||||
.replace(`/${appname}/api/listRecords/`, "")
|
.replace(`/api/listRecords/`, "/")
|
||||||
.replace(`/${appname}/api/aggregates/`, "")
|
.replace(`/api/aggregates/`, "/")
|
||||||
|
|
||||||
|
exports.getAppRelativePath = (appname, wholePath) => {
|
||||||
|
const builderInstanceRegex = new RegExp(
|
||||||
|
`\\/_builder\\/instance\\/[^\\/]*\\/[^\\/]*\\/`
|
||||||
|
)
|
||||||
|
|
||||||
|
return wholePath.replace(builderInstanceRegex, "/").replace(`/${appname}`, "")
|
||||||
|
}
|
||||||
|
|
|
@ -46,15 +46,29 @@ module.exports = (config, app) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.path.startsWith("/_builder/instance/_master")) {
|
if (ctx.path.startsWith("/_builder/instance/_master")) {
|
||||||
ctx.instance = ctx.master.getFullAccessApiForMaster()
|
const {
|
||||||
|
instance,
|
||||||
|
publicPath,
|
||||||
|
sharedPath,
|
||||||
|
} = await ctx.master.getFullAccessApiForMaster()
|
||||||
|
ctx.instance = instance
|
||||||
|
ctx.publicPath = publicPath
|
||||||
|
ctx.sharedPath = sharedPath
|
||||||
ctx.isAuthenticated = !!ctx.instance
|
ctx.isAuthenticated = !!ctx.instance
|
||||||
} else if (ctx.path.startsWith("/_builder/instance")) {
|
} else if (ctx.path.startsWith("/_builder/instance")) {
|
||||||
const builderAppName = pathParts[3]
|
const builderAppName = pathParts[3]
|
||||||
const instanceId = pathParts[4]
|
const instanceId = pathParts[4]
|
||||||
ctx.instance = ctx.master.getFullAccessApiForInstanceId(
|
const {
|
||||||
|
bbInstance,
|
||||||
|
publicPath,
|
||||||
|
sharedPath,
|
||||||
|
} = await ctx.master.getFullAccessApiForInstanceId(
|
||||||
builderAppName,
|
builderAppName,
|
||||||
instanceId
|
instanceId
|
||||||
).bbInstance
|
)
|
||||||
|
ctx.instance = bbInstance
|
||||||
|
ctx.publicPath = publicPath
|
||||||
|
ctx.sharedPath = sharedPath
|
||||||
ctx.isAuthenticated = !!ctx.instance
|
ctx.isAuthenticated = !!ctx.instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +101,7 @@ module.exports = (config, app) => {
|
||||||
.get("/_builder/*", async (ctx, next) => {
|
.get("/_builder/*", async (ctx, next) => {
|
||||||
const path = ctx.path.replace("/_builder", "")
|
const path = ctx.path.replace("/_builder", "")
|
||||||
|
|
||||||
if (path.startsWith("/api/")) {
|
if (path.startsWith("/api/") || path.startsWith("/instance/")) {
|
||||||
await next()
|
await next()
|
||||||
} else {
|
} else {
|
||||||
await send(ctx, path, { root: builderPath })
|
await send(ctx, path, { root: builderPath })
|
||||||
|
|
|
@ -147,17 +147,19 @@ const getComponentDefinitions = async (appPath, pages, componentLibrary) => {
|
||||||
|
|
||||||
const components = {}
|
const components = {}
|
||||||
const templates = {}
|
const templates = {}
|
||||||
|
const libraryPaths = {}
|
||||||
|
|
||||||
for (let library of componentLibraries) {
|
for (let library of componentLibraries) {
|
||||||
const info = await componentLibraryInfo(appPath, library)
|
const info = await componentLibraryInfo(appPath, library)
|
||||||
merge(components, info.components)
|
merge(components, info.components)
|
||||||
merge(templates, info.templates)
|
merge(templates, info.templates)
|
||||||
|
libraryPaths[library] = components._lib
|
||||||
}
|
}
|
||||||
|
|
||||||
if (components._lib) delete components._lib
|
if (components._lib) delete components._lib
|
||||||
if (templates._lib) delete templates._lib
|
if (templates._lib) delete templates._lib
|
||||||
|
|
||||||
return { components, templates }
|
return { components, templates, libraryPaths }
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getComponentDefinitions = getComponentDefinitions
|
module.exports.getComponentDefinitions = getComponentDefinitions
|
||||||
|
|
|
@ -156,7 +156,8 @@ module.exports = async context => {
|
||||||
|
|
||||||
const getFullAccessApiForInstanceId = async (appname, instanceId, appId) => {
|
const getFullAccessApiForInstanceId = async (appname, instanceId, appId) => {
|
||||||
if (!appId) {
|
if (!appId) {
|
||||||
appId = (await getApplication(appname)).id
|
const app = await getApplication(appname)
|
||||||
|
appId = app.id
|
||||||
}
|
}
|
||||||
const instanceKey = `/applications/${appId}/instances/${instanceId}`
|
const instanceKey = `/applications/${appId}/instances/${instanceId}`
|
||||||
const instance = await bb.recordApi.load(instanceKey)
|
const instance = await bb.recordApi.load(instanceKey)
|
||||||
|
@ -172,15 +173,25 @@ module.exports = async context => {
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
bbInstance: await getApisWithFullAccess(
|
bbInstance: await getApisWithFullAccess(
|
||||||
datastoreModule.getDatastore(dsConfig),
|
getInstanceDatastore(dsConfig),
|
||||||
appPackage
|
appPackage
|
||||||
),
|
),
|
||||||
instance,
|
instance,
|
||||||
|
publicPath: appPackage.mainUiPath,
|
||||||
|
sharedPath: appPackage.sharedPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFullAccessApiForMaster = async () =>
|
const getFullAccessApiForMaster = async () => {
|
||||||
await getApisWithFullAccess(masterDatastore, masterAppPackage(context))
|
const masterPkg = masterAppPackage(context)
|
||||||
|
const instance = await getApisWithFullAccess(masterDatastore, masterPkg)
|
||||||
|
|
||||||
|
return {
|
||||||
|
instance,
|
||||||
|
publicPath: masterPkg.unauthenticatedUiPath,
|
||||||
|
sharedPath: masterPkg.sharedPath,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const getInstanceApiForSession = async (appname, sessionId) => {
|
const getInstanceApiForSession = async (appname, sessionId) => {
|
||||||
if (isMaster(appname)) {
|
if (isMaster(appname)) {
|
||||||
|
|
Loading…
Reference in New Issue