From c2e9a03ac54443f4fe65651edbce74ad95e8ca7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Thu, 13 Oct 2022 16:29:58 +0200 Subject: [PATCH] fix(editor-ui): fix axios baseUrl when hosted under a subfolder (#4336) * fix(editor-ui): fix axios baseUrl when hosted under a subfolder * don't rewrite the favicon url twice * setup a base href for all relative urls * fix static urls --- packages/cli/src/Server.ts | 8 ++++---- packages/editor-ui/src/router.ts | 2 +- packages/editor-ui/src/store.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index b80b7053be..eb5da9492c 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -1798,11 +1798,11 @@ class App { const filePath = pathJoin(editorUiDistDir, fileName); if (/(index\.html)|.*\.(js|css)/.test(filePath) && existsSync(filePath)) { const srcFile = await readFile(filePath, 'utf8'); - let payload = srcFile.replace(basePathRegEx, n8nPath); + let payload = srcFile + .replace(basePathRegEx, n8nPath) + .replace(/\/static\//g, pathJoin(n8nPath, 'static/')); if (filePath.endsWith('index.html')) { - payload = payload - .replace(/\/favicon\.ico/g, `${n8nPath}favicon.ico`) - .replace(closingTitleTag, closingTitleTag + scriptsString); + payload = payload.replace(closingTitleTag, closingTitleTag + scriptsString); } const destFile = pathJoin(generatedStaticDir, fileName); await mkdir(pathDirname(destFile), { recursive: true }); diff --git a/packages/editor-ui/src/router.ts b/packages/editor-ui/src/router.ts index d5f8cc368c..24359f0d45 100644 --- a/packages/editor-ui/src/router.ts +++ b/packages/editor-ui/src/router.ts @@ -56,7 +56,7 @@ function getTemplatesRedirect(store: Store) { const router = new Router({ mode: 'history', // @ts-ignore - base: window.BASE_PATH === '/{{BASE_PATH}}/' ? '/' : window.BASE_PATH, + base: window.BASE_PATH ?? '/', scrollBehavior(to, from, savedPosition) { // saved position == null means the page is NOT visited from history (back button) if (savedPosition === null && to.name === VIEWS.TEMPLATES && to.meta) { diff --git a/packages/editor-ui/src/store.ts b/packages/editor-ui/src/store.ts index fe0e43efdf..acf40671db 100644 --- a/packages/editor-ui/src/store.ts +++ b/packages/editor-ui/src/store.ts @@ -58,7 +58,7 @@ const state: IRootState = { activeNode: null, activeCredentialType: null, // @ts-ignore - baseUrl: import.meta.env.VUE_APP_URL_BASE_API ? import.meta.env.VUE_APP_URL_BASE_API : (window.BASE_PATH === '/{{BASE_PATH}}/' ? '/' : window.BASE_PATH), + baseUrl: import.meta.env.VUE_APP_URL_BASE_API ?? window.BASE_PATH ?? '/', defaultLocale: 'en', endpointWebhook: 'webhook', endpointWebhookTest: 'webhook-test',