From 48f0f71f9504c7f98219bbc9027e0eeefffc855a Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 24 Dec 2021 07:59:14 +0100 Subject: [PATCH] :sparkles: Make it possible to disable the UI --- packages/cli/config/index.ts | 6 ++++ packages/cli/src/Server.ts | 54 +++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/packages/cli/config/index.ts b/packages/cli/config/index.ts index 50ebbe9668..32d67042fa 100644 --- a/packages/cli/config/index.ts +++ b/packages/cli/config/index.ts @@ -507,6 +507,12 @@ const config = convict({ env: 'N8N_ENDPOINT_WEBHOOK_TEST', doc: 'Path for test-webhook endpoint', }, + disableUi: { + format: Boolean, + default: false, + env: 'N8N_DISABLE_UI', + doc: 'Disable N8N UI (Frontend).', + }, disableProductionWebhooksOnMainProcess: { format: Boolean, default: false, diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index ffc180bc7b..549055fee6 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -2884,36 +2884,38 @@ class App { ); } - // Read the index file and replace the path placeholder - const editorUiPath = require.resolve('n8n-editor-ui'); - const filePath = pathJoin(pathDirname(editorUiPath), 'dist', 'index.html'); - const n8nPath = config.get('path'); + if (config.get('endpoints.disableUi') !== true) { + // Read the index file and replace the path placeholder + const editorUiPath = require.resolve('n8n-editor-ui'); + const filePath = pathJoin(pathDirname(editorUiPath), 'dist', 'index.html'); + const n8nPath = config.get('path'); - let readIndexFile = readFileSync(filePath, 'utf8'); - readIndexFile = readIndexFile.replace(/\/%BASE_PATH%\//g, n8nPath); - readIndexFile = readIndexFile.replace(/\/favicon.ico/g, `${n8nPath}favicon.ico`); + let readIndexFile = readFileSync(filePath, 'utf8'); + readIndexFile = readIndexFile.replace(/\/%BASE_PATH%\//g, n8nPath); + readIndexFile = readIndexFile.replace(/\/favicon.ico/g, `${n8nPath}favicon.ico`); - // Serve the altered index.html file separately - this.app.get(`/index.html`, async (req: express.Request, res: express.Response) => { - res.send(readIndexFile); - }); + // Serve the altered index.html file separately + this.app.get(`/index.html`, async (req: express.Request, res: express.Response) => { + res.send(readIndexFile); + }); - // Serve the website + // Serve the website + this.app.use( + '/', + express.static(pathJoin(pathDirname(editorUiPath), 'dist'), { + index: 'index.html', + setHeaders: (res, path) => { + if (res.req && res.req.url === '/index.html') { + // Set last modified date manually to n8n start time so + // that it hopefully refreshes the page when a new version + // got used + res.setHeader('Last-Modified', startTime); + } + }, + }), + ); + } const startTime = new Date().toUTCString(); - this.app.use( - '/', - express.static(pathJoin(pathDirname(editorUiPath), 'dist'), { - index: 'index.html', - setHeaders: (res, path) => { - if (res.req && res.req.url === '/index.html') { - // Set last modified date manually to n8n start time so - // that it hopefully refreshes the page when a new version - // got used - res.setHeader('Last-Modified', startTime); - } - }, - }), - ); } }