From 16a25a7cff78ed2718518d9ebc0e0802dc4170d7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 14 Jan 2021 17:01:31 +0000 Subject: [PATCH] When self hosting it is now possible to use a pretty URL to access the app rather than the normal appId. --- hosting/docker-compose.yaml | 8 +- hosting/hosting.properties | 1 - .../src/builderStore/store/frontend.js | 2 + .../builder/src/builderStore/store/hosting.js | 19 +- .../deploy/DeploymentHistory.svelte | 5 +- .../components/settings/tabs/General.svelte | 65 +- .../components/start/CreateAppModal.svelte | 6 +- .../server/src/api/controllers/application.js | 49 +- .../server/src/api/controllers/hosting.js | 5 + .../src/api/controllers/static/index.js | 27 +- packages/server/src/api/routes/hosting.js | 7 + packages/server/src/db/client.js | 1 + packages/server/src/environment.js | 2 + .../server/src/middleware/authenticated.js | 2 + packages/server/src/middleware/selfhost.js | 16 + .../server/src/utilities/builder/hosting.js | 21 + packages/server/src/utilities/index.js | 15 + packages/worker/package.json | 3 + packages/worker/src/api/controllers/app.js | 29 + packages/worker/src/api/controllers/deploy.js | 2 +- packages/worker/src/api/routes/app.js | 9 + packages/worker/src/api/routes/index.js | 3 +- packages/worker/src/db/index.js | 16 + packages/worker/src/environment.js | 8 +- packages/worker/src/middleware/check-key.js | 10 +- packages/worker/yarn.lock | 691 +++++++++++++++++- 26 files changed, 964 insertions(+), 58 deletions(-) create mode 100644 packages/server/src/middleware/selfhost.js create mode 100644 packages/worker/src/api/controllers/app.js create mode 100644 packages/worker/src/api/routes/app.js create mode 100644 packages/worker/src/db/index.js diff --git a/hosting/docker-compose.yaml b/hosting/docker-compose.yaml index c4a6c669b3..5b7c266c1e 100644 --- a/hosting/docker-compose.yaml +++ b/hosting/docker-compose.yaml @@ -6,8 +6,11 @@ services: ports: - "${APP_PORT}:4002" environment: - SELF_HOSTED: 1 + SELF_HOSTED: 1 + CLOUD: 1 COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984 + WORKER_URL: http://worker-service:4003 + HOSTING_KEY: ${HOSTING_KEY} BUDIBASE_ENVIRONMENT: ${BUDIBASE_ENVIRONMENT} PORT: 4002 JWT_SECRET: ${JWT_SECRET} @@ -20,14 +23,13 @@ services: - "${WORKER_PORT}:4003" environment: SELF_HOSTED: 1, - DEPLOYMENT_API_KEY: ${WORKER_API_KEY} PORT: 4003 MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY} MINIO_SECRET_KEY: ${MINIO_SECRET_KEY} RAW_MINIO_URL: http://minio-service:9000 COUCH_DB_USERNAME: ${COUCH_DB_USER} COUCH_DB_PASSWORD: ${COUCH_DB_PASSWORD} - RAW_COUCH_DB_URL: http://couchdb-service:5984 + COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984 SELF_HOST_KEY: ${HOSTING_KEY} depends_on: - minio-service diff --git a/hosting/hosting.properties b/hosting/hosting.properties index 2ef83543a4..ad047a3826 100644 --- a/hosting/hosting.properties +++ b/hosting/hosting.properties @@ -12,7 +12,6 @@ MINIO_ACCESS_KEY=budibase MINIO_SECRET_KEY=budibase COUCH_DB_PASSWORD=budibase COUCH_DB_USER=budibase -WORKER_API_KEY=budibase # This section contains variables that do not need to be altered under normal circumstances APP_PORT=4002 diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 501725f029..2082a3e49b 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -28,6 +28,7 @@ import { const INITIAL_FRONTEND_STATE = { apps: [], name: "", + url: "", description: "", layouts: [], screens: [], @@ -62,6 +63,7 @@ export const getFrontendStore = () => { libraries: pkg.application.componentLibraries, components, name: pkg.application.name, + url: pkg.application.url, description: pkg.application.description, appId: pkg.application._id, layouts, diff --git a/packages/builder/src/builderStore/store/hosting.js b/packages/builder/src/builderStore/store/hosting.js index 36067773b5..d265eeddff 100644 --- a/packages/builder/src/builderStore/store/hosting.js +++ b/packages/builder/src/builderStore/store/hosting.js @@ -1,13 +1,16 @@ import { writable } from "svelte/store" -import api from "../api" +import api, {get} from "../api" -const INITIAL_BACKEND_UI_STATE = { +const INITIAL_HOSTING_UI_STATE = { hostingInfo: {}, appUrl: "", + deployedApps: {}, + deployedAppNames: [], + deployedAppUrls: [], } export const getHostingStore = () => { - const store = writable({ ...INITIAL_BACKEND_UI_STATE }) + const store = writable({ ...INITIAL_HOSTING_UI_STATE }) store.actions = { fetch: async () => { const responses = await Promise.all([ @@ -33,6 +36,16 @@ export const getHostingStore = () => { return state }) }, + fetchDeployedApps: async () => { + let deployments = await (await get("/api/hosting/apps")).json() + store.update(state => { + state.deployedApps = deployments + state.deployedAppNames = Object.values(deployments).map(app => app.name) + state.deployedAppUrls = Object.values(deployments).map(app => app.url) + return state + }) + return deployments + } } return store } diff --git a/packages/builder/src/components/deploy/DeploymentHistory.svelte b/packages/builder/src/components/deploy/DeploymentHistory.svelte index fe95b1369f..e65ddf80cf 100644 --- a/packages/builder/src/components/deploy/DeploymentHistory.svelte +++ b/packages/builder/src/components/deploy/DeploymentHistory.svelte @@ -6,7 +6,7 @@ import api from "builderStore/api" import { notifier } from "builderStore/store/notifications" import CreateWebhookDeploymentModal from "./CreateWebhookDeploymentModal.svelte" - import { hostingStore } from "builderStore" + import { store, hostingStore } from "builderStore" const DeploymentStatus = { SUCCESS: "SUCCESS", @@ -36,7 +36,8 @@ let errorReason let poll let deployments = [] - let deploymentUrl = `${$hostingStore.appUrl}/${appId}` + let urlComponent = $hostingStore.hostingInfo.type === "self" ? $store.url : `/${appId}` + let deploymentUrl = `${$hostingStore.appUrl}${urlComponent}` const formatDate = (date, format) => Intl.DateTimeFormat("en-GB", DATE_OPTIONS[format]).format(date) diff --git a/packages/builder/src/components/settings/tabs/General.svelte b/packages/builder/src/components/settings/tabs/General.svelte index 809917f27d..3852f7dc8d 100644 --- a/packages/builder/src/components/settings/tabs/General.svelte +++ b/packages/builder/src/components/settings/tabs/General.svelte @@ -1,11 +1,20 @@
@@ -21,8 +68,18 @@ on:save={e => updateApplication({ name: e.detail })} thin edit - value={$store.name} + bind:value={$store.name} + bind:error={nameError} label="App Name" /> + {#if $hostingStore.hostingInfo.type === "self"} + updateApplication({ url: e.detail })} + thin + edit + bind:value={$store.url} + bind:error={urlError} + label="App URL" /> + {/if}