serving files from _shared

This commit is contained in:
Michael Shanks 2019-09-12 15:55:36 +01:00
parent 4cd2de5df3
commit 5f2865b09a
35 changed files with 85 additions and 47 deletions

View File

@ -527,7 +527,7 @@
"props": { "props": {
"main": { "main": {
"_component": "@budibase/standard-components/login", "_component": "@budibase/standard-components/login",
"logo": "/assets/budibase-logo.png", "logo": "/_shared/budibase-logo.png",
"loginRedirect": "", "loginRedirect": "",
"usernameLabel": "Username", "usernameLabel": "Username",
"passwordLabel": "Password", "passwordLabel": "Password",
@ -535,7 +535,7 @@
}, },
"unauthenticated": { "unauthenticated": {
"_component": "@budibase/standard-components/login", "_component": "@budibase/standard-components/login",
"logo": "/assets/budibase-logo.png", "logo": "/_shared/budibase-logo.png",
"loginRedirect": "", "loginRedirect": "",
"usernameLabel": "Username", "usernameLabel": "Username",
"passwordLabel": "Password", "passwordLabel": "Password",

View File

@ -3,7 +3,7 @@
"description": "", "description": "",
"inherits": "@budibase/standard-components/login", "inherits": "@budibase/standard-components/login",
"props": { "props": {
"logo": "/assets/budibase-logo.png" "logo": "/_shared/budibase-logo.png"
}, },
"tags": [ "tags": [
"login", "login",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<meta name='viewport' content='width=device-width'> <meta name='viewport' content='width=device-width'>
<title>Budibase</title> <title>Budibase</title>
<link rel='icon' type='image/png' href='/_master//assets/favicon.png'> <link rel='icon' type='image/png' href='/_master/_shared/favicon.png'>
<script src='/_master/clientAppDefinition.js'></script> <script src='/_master/clientAppDefinition.js'></script>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<meta name='viewport' content='width=device-width'> <meta name='viewport' content='width=device-width'>
<title>Budibase - Login</title> <title>Budibase - Login</title>
<link rel='icon' type='image/png' href='/_master//assets/favicon.png'> <link rel='icon' type='image/png' href='/_master/_shared/favicon.png'>
<script src='/_master/clientAppDefinition.js'></script> <script src='/_master/clientAppDefinition.js'></script>

View File

@ -0,0 +1 @@
hello

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
window['##BUDIBASE_APPDEFINITION##'] = {"hierarchy":{"name":"root","type":"root","children":[{"name":"customer","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"name","getInitialValue":"default","getUndefinedValue":"default"}],"children":[{"name":"invoiceyooo","type":"record","fields":[{"name":"amount","type":"number","typeOptions":{"minValue":99999999999,"maxValue":99999999999,"decimalPlaces":2},"label":"amount","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":2,"indexes":[],"allidsShardFactor":1,"collectionName":"invoices","isSingle":false}],"validationRules":[],"nodeId":1,"indexes":[],"allidsShardFactor":64,"collectionName":"customers","isSingle":false}],"pathMaps":[],"indexes":[],"nodeId":0},"componentLibraries":["./customComponents","./moreCustomComponents","@budibase/standard-components"],"appRootPath":"","props":{"_component":"some_component"}} window['##BUDIBASE_APPDEFINITION##'] = {"hierarchy":{"name":"root","type":"root","children":[{"name":"customer","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"name","getInitialValue":"default","getUndefinedValue":"default"}],"children":[{"name":"invoiceyooo","type":"record","fields":[{"name":"amount","type":"number","typeOptions":{"minValue":99999999999,"maxValue":99999999999,"decimalPlaces":2},"label":"amount","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":2,"indexes":[],"allidsShardFactor":1,"collectionName":"invoices","isSingle":false}],"validationRules":[],"nodeId":1,"indexes":[],"allidsShardFactor":64,"collectionName":"customers","isSingle":false}],"pathMaps":[],"indexes":[],"nodeId":0},"componentLibraries":[{"importPath":"/lib/customComponents/index.js","libName":"./customComponents"},{"importPath":"/lib/moreCustomComponents/index.js","libName":"./moreCustomComponents"},{"importPath":"/lib/node_modules/@budibase/standard-components/dist/index.js","libName":"@budibase/standard-components"}],"appRootPath":"","props":{"_component":"some_component"}}

View File

@ -5,17 +5,18 @@
<meta name='viewport' content='width=device-width'> <meta name='viewport' content='width=device-width'>
<title>Budibase App</title> <title>Budibase App</title>
<link rel='icon' type='image/png' href='//assets/favicon.png'> <link rel='icon' type='image/png' href='//_shared/favicon.png'>
<link rel='stylesheet' href='https://css-r-us.com/myawesomestyles.css'> <link rel='stylesheet' href='https://css-r-us.com/myawesomestyles.css'>
<link rel='stylesheet' href='///local.css'> <link rel='stylesheet' href='///local.css'>
<script src='/clientAppDefinition.js'></script>
<script src='/budibase-client.js'></script> <script src='/budibase-client.js'></script>
</head> </head>
<body id="app"> <body id="app">
<script src='/clientAppDefinition.js'></script>
</body> </body>
</html> </html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
window['##BUDIBASE_APPDEFINITION##'] = {"hierarchy":{"name":"root","type":"root","children":[{"name":"customer","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"name","getInitialValue":"default","getUndefinedValue":"default"}],"children":[{"name":"invoiceyooo","type":"record","fields":[{"name":"amount","type":"number","typeOptions":{"minValue":99999999999,"maxValue":99999999999,"decimalPlaces":2},"label":"amount","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":2,"indexes":[],"allidsShardFactor":1,"collectionName":"invoices","isSingle":false}],"validationRules":[],"nodeId":1,"indexes":[],"allidsShardFactor":64,"collectionName":"customers","isSingle":false}],"pathMaps":[],"indexes":[],"nodeId":0},"componentLibraries":["./customComponents","./moreCustomComponents","@budibase/standard-components"],"appRootPath":"","props":{"_component":"some_other_component"}} window['##BUDIBASE_APPDEFINITION##'] = {"hierarchy":{"name":"root","type":"root","children":[{"name":"customer","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"name","getInitialValue":"default","getUndefinedValue":"default"}],"children":[{"name":"invoiceyooo","type":"record","fields":[{"name":"amount","type":"number","typeOptions":{"minValue":99999999999,"maxValue":99999999999,"decimalPlaces":2},"label":"amount","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":2,"indexes":[],"allidsShardFactor":1,"collectionName":"invoices","isSingle":false}],"validationRules":[],"nodeId":1,"indexes":[],"allidsShardFactor":64,"collectionName":"customers","isSingle":false}],"pathMaps":[],"indexes":[],"nodeId":0},"componentLibraries":[{"importPath":"/lib/customComponents/index.js","libName":"./customComponents"},{"importPath":"/lib/moreCustomComponents/index.js","libName":"./moreCustomComponents"},{"importPath":"/lib/node_modules/@budibase/standard-components/dist/index.js","libName":"@budibase/standard-components"}],"appRootPath":"","props":{"_component":"some_other_component"}}

View File

@ -5,17 +5,18 @@
<meta name='viewport' content='width=device-width'> <meta name='viewport' content='width=device-width'>
<title>Test App 1 - Login</title> <title>Test App 1 - Login</title>
<link rel='icon' type='image/png' href='//assets/favicon.png'> <link rel='icon' type='image/png' href='//_shared/favicon.png'>
<link rel='stylesheet' href='https://css-r-us.com/myawesomestyles.css'> <link rel='stylesheet' href='https://css-r-us.com/myawesomestyles.css'>
<link rel='stylesheet' href='///local.css'> <link rel='stylesheet' href='///local.css'>
<script src='/clientAppDefinition.js'></script>
<script src='/budibase-client.js'></script> <script src='/budibase-client.js'></script>
</head> </head>
<body id="app"> <body id="app">
<script src='/clientAppDefinition.js'></script>
</body> </body>
</html> </html>

View File

@ -159,7 +159,7 @@
"main": {}, "main": {},
"unauthenticated": { "unauthenticated": {
"_component": "budibase-standard-components/login", "_component": "budibase-standard-components/login",
"logo": "/assets/budibase-logo.png", "logo": "/_shared/budibase-logo.png",
"loginRedirect": "", "loginRedirect": "",
"usernameLabel": "Username", "usernameLabel": "Username",
"passwordLabel": "Password", "passwordLabel": "Password",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<meta name='viewport' content='width=device-width'> <meta name='viewport' content='width=device-width'>
<title>Budibase App</title> <title>Budibase App</title>
<link rel='icon' type='image/png' href='/testApp2//assets/favicon.png'> <link rel='icon' type='image/png' href='/testApp2/_shared/favicon.png'>
<script src='/testApp2/budibase-client.js'></script> <script src='/testApp2/budibase-client.js'></script>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
window['##BUDIBASE_APPDEFINITION##'] = {"hierarchy":{"name":"root","type":"root","children":[{"name":"customer","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"name","getInitialValue":"default","getUndefinedValue":"default"}],"children":[{"name":"invoiceyooo","type":"record","fields":[{"name":"amount","type":"number","typeOptions":{"minValue":99999999999,"maxValue":99999999999,"decimalPlaces":2},"label":"amount","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":2,"indexes":[],"allidsShardFactor":1,"collectionName":"invoices","isSingle":false}],"validationRules":[],"nodeId":1,"indexes":[{"name":"customer_invoices","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[2],"nodeId":5}],"allidsShardFactor":64,"collectionName":"customers","isSingle":false}],"pathMaps":[],"indexes":[{"name":"Yeo index","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[1],"nodeId":4},{"name":"everyones_invoices","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[2],"nodeId":6}],"nodeId":0},"componentLibraries":["budibase-standard-components"],"appRootPath":"/testApp2","props":{"_component":"budibase-standard-components/login","logo":"/assets/budibase-logo.png","loginRedirect":"","usernameLabel":"Username","passwordLabel":"Password","loginButtonLabel":"Login"}} window['##BUDIBASE_APPDEFINITION##'] = {"hierarchy":{"name":"root","type":"root","children":[{"name":"customer","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"name","getInitialValue":"default","getUndefinedValue":"default"}],"children":[{"name":"invoiceyooo","type":"record","fields":[{"name":"amount","type":"number","typeOptions":{"minValue":99999999999,"maxValue":99999999999,"decimalPlaces":2},"label":"amount","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":2,"indexes":[],"allidsShardFactor":1,"collectionName":"invoices","isSingle":false}],"validationRules":[],"nodeId":1,"indexes":[{"name":"customer_invoices","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[2],"nodeId":5}],"allidsShardFactor":64,"collectionName":"customers","isSingle":false}],"pathMaps":[],"indexes":[{"name":"Yeo index","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[1],"nodeId":4},{"name":"everyones_invoices","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[2],"nodeId":6}],"nodeId":0},"componentLibraries":["budibase-standard-components"],"appRootPath":"/testApp2","props":{"_component":"budibase-standard-components/login","logo":"/_shared/budibase-logo.png","loginRedirect":"","usernameLabel":"Username","passwordLabel":"Password","loginButtonLabel":"Login"}}

View File

@ -5,7 +5,7 @@
<meta name='viewport' content='width=device-width'> <meta name='viewport' content='width=device-width'>
<title>Test App Two</title> <title>Test App Two</title>
<link rel='icon' type='image/png' href='/testApp2//assets/favicon.png'> <link rel='icon' type='image/png' href='/testApp2/_shared/favicon.png'>
<script src='/testApp2/budibase-client.js'></script> <script src='/testApp2/budibase-client.js'></script>

View File

@ -2,8 +2,8 @@ const {initialiseData, setupDatastore} = require("@budibase/core");
const constructHierarchy = require("../utilities/constructHierarchy"); const constructHierarchy = require("../utilities/constructHierarchy");
const getDatabaseManager = require("../utilities/databaseManager"); const getDatabaseManager = require("../utilities/databaseManager");
const {getApisForUser, getApisWithFullAccess} = require("../utilities/budibaseApi"); const {getApisForUser, getApisWithFullAccess} = require("../utilities/budibaseApi");
const masterDbAppDefinition = require("../appPackages/master/appDefinition.json"); const masterDbAppDefinition = require("../appPackages/_master/appDefinition.json");
const masterDbAccessLevels = require("../appPackages/master/access_levels.json"); const masterDbAccessLevels = require("../appPackages/_master/access_levels.json");
const { masterAppPackage } = require("../utilities/createAppPackage"); const { masterAppPackage } = require("../utilities/createAppPackage");
module.exports = async (context, datastoreModule, username, password) => { module.exports = async (context, datastoreModule, username, password) => {

View File

@ -50,6 +50,7 @@ module.exports = (config, app) => {
ctx.instance = instance.instance; ctx.instance = instance.instance;
ctx.publicPath = instance.publicPath; ctx.publicPath = instance.publicPath;
ctx.sharedPath = instance.sharedPath;
ctx.isAuthenticated = !!instance.instance; ctx.isAuthenticated = !!instance.instance;
await next(); await next();
@ -210,7 +211,13 @@ module.exports = (config, app) => {
if(path.startsWith("/api/")) { if(path.startsWith("/api/")) {
await next(); await next();
} else { } else if(path.startsWith("/_shared/")) {
await send(
ctx,
path.replace(`/_shared/`, ""),
{ root: ctx.sharedPath });
}
else {
await send(ctx, path, { root: ctx.publicPath }); await send(ctx, path, { root: ctx.publicPath });
} }
}) })
@ -347,8 +354,8 @@ module.exports = (config, app) => {
ctx.body ctx.body
); );
ctx.response.status = StatusCodes.OK; ctx.response.status = StatusCodes.OK;
}) });
.post("/:appname/api/actionsAndTriggers", async (ctx) => { /*.post("/:appname/api/actionsAndTriggers", async (ctx) => {
ctx.body = await ctx.instance.templateApi.saveApplicationHierarchy( ctx.body = await ctx.instance.templateApi.saveApplicationHierarchy(
ctx.body ctx.body
); );
@ -359,7 +366,7 @@ module.exports = (config, app) => {
ctx.body ctx.body
); );
ctx.response.status = StatusCodes.OK; ctx.response.status = StatusCodes.OK;
}); })*/
const getRecordKey = (appname, wholePath) => const getRecordKey = (appname, wholePath) =>
wholePath wholePath

View File

@ -4,7 +4,7 @@ const { readFile } = require("fs-extra");
const { hierarchy } = require("@budibase/core"); const { hierarchy } = require("@budibase/core");
const { take } = require("lodash/fp"); const { take } = require("lodash/fp");
const masterAppDefinition = constructHierarchy( const masterAppDefinition = constructHierarchy(
require("../appPackages/master/appDefinition.json")); require("../appPackages/_master/appDefinition.json"));
const {getApisWithFullAccess} = require("../utilities/budibaseApi"); const {getApisWithFullAccess} = require("../utilities/budibaseApi");
const { createTarGzPackage } = require("../utilities/targzAppPackage"); const { createTarGzPackage } = require("../utilities/targzAppPackage");
const { timeout } = require("./helpers"); const { timeout } = require("./helpers");

View File

@ -3,7 +3,7 @@ const constructHierarchy = require("../utilities/constructHierarchy");
const { readFile } = require("fs-extra"); const { readFile } = require("fs-extra");
const {getRecordApi, getAuthApi} = require("@budibase/core"); const {getRecordApi, getAuthApi} = require("@budibase/core");
const masterAppDefinition = constructHierarchy( const masterAppDefinition = constructHierarchy(
require("../appPackages/master/appDefinition.json")); require("../appPackages/_master/appDefinition.json"));
const {getApisWithFullAccess} = require("../utilities/budibaseApi"); const {getApisWithFullAccess} = require("../utilities/budibaseApi");
const { createTarGzPackage } = require("../utilities/targzAppPackage"); const { createTarGzPackage } = require("../utilities/targzAppPackage");
const { timeout } = require("./helpers"); const { timeout } = require("./helpers");

View File

@ -45,4 +45,26 @@ module.exports = (app) => {
}); });
it("should serve file from shared when authenticated", async () => {
const response = await app.get("/testApp/_shared/shared_file.txt")
.set("cookie", app.credentials.testAppUser1.cookie)
.expect(statusCodes.OK);
const expectedFile = await readFile("appPackages/testApp/public/_shared/shared_file.txt", "utf8");
expect(response.text).toBe(expectedFile);
});
it("should serve file from shared when not authenticated", async () => {
const response = await app.get("/testApp/_shared/shared_file.txt")
.expect(statusCodes.OK);
const expectedFile = await readFile("appPackages/testApp/public/_shared/shared_file.txt", "utf8");
expect(response.text).toBe(expectedFile);
});
} }

View File

@ -100,7 +100,7 @@ module.exports = () => {
testAppInfo: { testAppInfo: {
name: "testApp" name: "testApp"
}, },
destroy: () => server.destroy(), destroy: () => server && server.destroy(),
masterAppPackage: masterAppPackage({ config }), masterAppPackage: masterAppPackage({ config }),
testAppInstance1AppPackage: async (app) => applictionVersionPackage( testAppInstance1AppPackage: async (app) => applictionVersionPackage(
await buildAppContext(config, true), await buildAppContext(config, true),

View File

@ -64,7 +64,7 @@ const buildIndexHtml = async (config, appname, appPath, pages, pageName) => {
const templateObj = { const templateObj = {
title: pages[pageName].index.title || "Budibase App", title: pages[pageName].index.title || "Budibase App",
favicon: `${appRootPath}/${pages[pageName].index.favicon || "/assets/favicon.png"}`, favicon: `${appRootPath}/${pages[pageName].index.favicon || "/_shared/favicon.png"}`,
stylesheets: (pages.stylesheets || []).map(stylesheetUrl), stylesheets: (pages.stylesheets || []).map(stylesheetUrl),
appRootPath appRootPath
} }

View File

@ -56,7 +56,8 @@ module.exports.masterAppPackage = (context) => {
: plugins, : plugins,
appPath: standardPackage.appPath, appPath: standardPackage.appPath,
unauthenticatedUiPath: standardPackage.unauthenticatedUiPath, unauthenticatedUiPath: standardPackage.unauthenticatedUiPath,
mainUiPath: standardPackage.mainUiPath mainUiPath: standardPackage.mainUiPath,
sharedPath: standardPackage.sharedPath
}); });
} }
@ -67,7 +68,9 @@ const publicPaths = (appPath) => ({
mainUiPath: resolve(join( mainUiPath: resolve(join(
__dirname, appPath, "public", "main")), __dirname, appPath, "public", "main")),
unauthenticatedUiPath: resolve(join( unauthenticatedUiPath: resolve(join(
__dirname, appPath, "public", "unauthenticated")) __dirname, appPath, "public", "unauthenticated")),
sharedPath: resolve(join(
__dirname, appPath, "public", "_shared"))
}); });

View File

@ -152,14 +152,16 @@ module.exports = async (context) => {
masterDatastore, masterDatastore,
masterAppPackage(context), masterAppPackage(context),
session), session),
publicPath: masterPkg.mainUiPath publicPath: masterPkg.mainUiPath,
sharedPath: masterPkg.sharedPath
}); });
} catch(_) { } catch(_) {
return ({ return ({
instance: null, instance: null,
publicPath: masterPkg.unauthenticatedUiPath publicPath: masterPkg.unauthenticatedUiPath,
sharedPath: masterPkg.sharedPath
}); });
} }
} }
@ -183,15 +185,18 @@ module.exports = async (context) => {
instanceDatastore, instanceDatastore,
appPackage, appPackage,
session), session),
publicPath: appPackage.mainUiPath publicPath: appPackage.mainUiPath,
sharedPath: appPackage.sharedPath
}); });
} catch(_) { } catch(_) {
const appPublicPaths = applictionVersionPublicPaths(
app.name,
app.defaultVersion.id);
return ({ return ({
instance:null, instance:null,
publicPath: applictionVersionPublicPaths( publicPath: appPublicPaths.unauthenticatedUiPath,
app.name, sharedPath: appPublicPaths.sharedPath
app.defaultVersion.id).unauthenticatedUiPath
}); });
} }
} }