From 04f49fd7b936a5d10db2b300483d974a2af23b5c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 16 Aug 2022 09:25:16 +0000 Subject: [PATCH 1/4] Proxy vite HMR websocket in dev --- hosting/nginx.dev.conf.hbs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hosting/nginx.dev.conf.hbs b/hosting/nginx.dev.conf.hbs index 9398b7e719..91f495cfac 100644 --- a/hosting/nginx.dev.conf.hbs +++ b/hosting/nginx.dev.conf.hbs @@ -77,6 +77,11 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } + location /ws { + proxy_pass http://{{ address }}:3000; + rewrite ^/ws(.*)$ /$1 break; + } + location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; From 4645901309b7bb2a4bb465cf75b9baf841980a45 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 16 Aug 2022 09:26:23 +0000 Subject: [PATCH 2/4] Support env variables for vite config --- packages/builder/vite.config.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/builder/vite.config.js b/packages/builder/vite.config.js index 56ffbf20f5..9859e1dbb9 100644 --- a/packages/builder/vite.config.js +++ b/packages/builder/vite.config.js @@ -1,15 +1,22 @@ import { svelte } from "@sveltejs/vite-plugin-svelte" import replace from "@rollup/plugin-replace" +import { defineConfig, loadEnv } from "vite" import path from "path" -export default ({ mode }) => { +export default defineConfig(({ mode }) => { const isProduction = mode === "production" + const env = loadEnv(mode, process.cwd()) return { server: { fs: { strict: false, }, + hmr: { + protocol: "wss", + clientPort: env.VITE_HMR_CLIENT_PORT || 3000, + path: env.VITE_HMR_PATH || "/" + } }, base: "/builder/", build: { @@ -79,4 +86,4 @@ export default ({ mode }) => { ], }, } -} +}) From 2a6719d3acb40ece69f88961e912de4c03ce81f4 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 16 Aug 2022 14:02:51 +0000 Subject: [PATCH 3/4] Only watch plugins in single tenant envs --- packages/server/src/app.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index 2f8adc879d..6f63715cfb 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -25,7 +25,7 @@ import * as migrations from "./migrations" import { events, installation, tenancy } from "@budibase/backend-core" import { createAdminUser, getChecklist } from "./utilities/workerRequests" import { processPlugin } from "./api/controllers/plugin" -import { getGlobalDB } from "@budibase/backend-core/tenancy" +import { DEFAULT_TENANT_ID } from "@budibase/backend-core/constants" const app = new Koa() @@ -138,7 +138,7 @@ module.exports = server.listen(env.PORT || 0, async () => { } // monitor plugin directory if required - if (env.SELF_HOSTED && env.PLUGINS_DIR && fs.existsSync(env.PLUGINS_DIR)) { + if (env.SELF_HOSTED && !env.MULTI_TENANCY && env.PLUGINS_DIR && fs.existsSync(env.PLUGINS_DIR)) { const watchPath = path.join(env.PLUGINS_DIR, "./**/dist/*.tar.gz") chokidar .watch(watchPath, { @@ -146,8 +146,7 @@ module.exports = server.listen(env.PORT || 0, async () => { awaitWriteFinish: true, }) .on("all", async (event: string, path: string) => { - const tenantId = tenancy.getTenantId() - await tenancy.doInTenant(tenantId, async () => { + await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { try { const split = path.split("/") const name = split[split.length - 1] From bb19810e361cee0714698f6a11c585fbdd20c09e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 16 Aug 2022 14:42:32 +0000 Subject: [PATCH 4/4] Add missing declaration of objectstore module --- packages/server/src/module.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/src/module.d.ts b/packages/server/src/module.d.ts index 4c0e13586a..eb1d1feb48 100644 --- a/packages/server/src/module.d.ts +++ b/packages/server/src/module.d.ts @@ -10,3 +10,4 @@ declare module "@budibase/backend-core/sessions" declare module "@budibase/backend-core/encryption" declare module "@budibase/backend-core/utils" declare module "@budibase/backend-core/redis" +declare module "@budibase/backend-core/objectStore"