diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 3a6ffaad6de48..e35648b1c0500 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -10,7 +10,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ - +import assert from 'assert'; import { exec as callbackExec } from 'child_process'; import { access as fsAccess } from 'fs/promises'; import os from 'os'; @@ -452,6 +452,11 @@ class Server extends AbstractServer { ...excludeEndpoints.split(':'), ].filter((u) => !!u); + assert( + !ignoredEndpoints.includes(this.restEndpoint), + `REST endpoint cannot be set to any of these values: ${ignoredEndpoints.join()} `, + ); + // eslint-disable-next-line no-useless-escape const authIgnoreRegex = new RegExp(`^\/(${ignoredEndpoints.join('|')})\/?.*$`); diff --git a/packages/cli/src/commands/start.ts b/packages/cli/src/commands/start.ts index db53900de2393..359c79d584d54 100644 --- a/packages/cli/src/commands/start.ts +++ b/packages/cli/src/commands/start.ts @@ -144,6 +144,7 @@ export class Start extends BaseCommand { private async generateStaticAssets() { // Read the index file and replace the path placeholder const n8nPath = config.getEnv('path'); + const restEndpoint = config.getEnv('endpoints.rest'); const hooksUrls = config.getEnv('externalFrontendHooksUrls'); let scriptsString = ''; @@ -167,6 +168,7 @@ export class Start extends BaseCommand { ]; if (filePath.endsWith('index.html')) { streams.push( + replaceStream('{{REST_ENDPOINT}}', restEndpoint, { ignoreCase: false }), replaceStream(closingTitleTag, closingTitleTag + scriptsString, { ignoreCase: false, }), diff --git a/packages/editor-ui/index.html b/packages/editor-ui/index.html index 35923d36b5a52..12dbfaeb9dc06 100644 --- a/packages/editor-ui/index.html +++ b/packages/editor-ui/index.html @@ -7,6 +7,7 @@ diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 659b5d97c73be..38003cb123a90 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -985,6 +985,7 @@ export interface WorkflowsState { export interface RootState { baseUrl: string; + restEndpoint: string; defaultLocale: string; endpointWebhook: string; endpointWebhookTest: string; diff --git a/packages/editor-ui/src/shims.d.ts b/packages/editor-ui/src/shims.d.ts index f26c77ce8f720..c231305c43c1c 100644 --- a/packages/editor-ui/src/shims.d.ts +++ b/packages/editor-ui/src/shims.d.ts @@ -11,12 +11,12 @@ declare global { PROD: boolean; NODE_ENV: 'development' | 'production'; VUE_APP_URL_BASE_API: string; - VUE_APP_ENDPOINT_REST?: string; }; } interface Window { BASE_PATH: string; + REST_ENDPOINT: string; } namespace JSX { diff --git a/packages/editor-ui/src/stores/n8nRootStore.ts b/packages/editor-ui/src/stores/n8nRootStore.ts index e8b72a4e7936a..8abd800004797 100644 --- a/packages/editor-ui/src/stores/n8nRootStore.ts +++ b/packages/editor-ui/src/stores/n8nRootStore.ts @@ -5,12 +5,16 @@ import { defineStore } from 'pinia'; import Vue from 'vue'; import { useNodeTypesStore } from './nodeTypes'; -const { VUE_APP_URL_BASE_API, VUE_APP_ENDPOINT_REST } = import.meta.env; +const { VUE_APP_URL_BASE_API } = import.meta.env; export const useRootStore = defineStore(STORES.ROOT, { state: (): RootState => ({ baseUrl: VUE_APP_URL_BASE_API ?? (window.BASE_PATH === '/{{BASE_PATH}}/' ? '/' : window.BASE_PATH), + restEndpoint: + !window.REST_ENDPOINT || window.REST_ENDPOINT === '{{REST_ENDPOINT}}' + ? 'rest' + : window.REST_ENDPOINT, defaultLocale: 'en', endpointWebhook: 'webhook', endpointWebhookTest: 'webhook-test', @@ -41,20 +45,12 @@ export const useRootStore = defineStore(STORES.ROOT, { }, getRestUrl(): string { - let endpoint = 'rest'; - if (VUE_APP_ENDPOINT_REST) { - endpoint = VUE_APP_ENDPOINT_REST; - } - return `${this.baseUrl}${endpoint}`; + return `${this.baseUrl}${this.restEndpoint}`; }, getRestApiContext(): IRestApiContext { - let endpoint = 'rest'; - if (VUE_APP_ENDPOINT_REST) { - endpoint = VUE_APP_ENDPOINT_REST; - } return { - baseUrl: `${this.baseUrl}${endpoint}`, + baseUrl: this.getRestUrl, sessionId: this.sessionId, }; },