From 369e8084d3317fc803d2a772362ba59ba7e2c228 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Tue, 15 Oct 2019 07:21:15 +0200 Subject: [PATCH] :zap: Make it possible to set tunnel subdomain via environment variable --- packages/cli/commands/start.ts | 14 +++++++++++--- packages/core/src/Constants.ts | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index a81f684f24..56773f5b29 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -1,5 +1,6 @@ import * as localtunnel from 'localtunnel'; import { + TUNNEL_SUBDOMAIN_ENV, UserSettings, } from "n8n-core"; import { Command, flags } from '@oclif/command'; @@ -14,8 +15,8 @@ import { GenericHelpers, LoadNodesAndCredentials, NodeTypes, - TestWebhooks, Server, + TestWebhooks, } from "../src"; const tunnel = promisify(localtunnel); @@ -120,7 +121,14 @@ export class Start extends Command { if (flags.tunnel === true) { this.log('\nWaiting for tunnel ...'); - if (userSettings.tunnelSubdomain === undefined) { + let tunnelSubdomain; + if (process.env[TUNNEL_SUBDOMAIN_ENV] !== undefined && process.env[TUNNEL_SUBDOMAIN_ENV] !== '') { + tunnelSubdomain = process.env[TUNNEL_SUBDOMAIN_ENV]; + } else if (userSettings.tunnelSubdomain !== undefined) { + tunnelSubdomain = userSettings.tunnelSubdomain; + } + + if (tunnelSubdomain === undefined) { // When no tunnel subdomain did exist yet create a new random one const availableCharacters = 'abcdefghijklmnopqrstuvwxyz0123456789'; userSettings.tunnelSubdomain = Array.from({ length: 24 }).map(() => { @@ -132,7 +140,7 @@ export class Start extends Command { const tunnelSettings: localtunnel.TunnelConfig = { host: 'https://hooks.n8n.cloud', - subdomain: userSettings.tunnelSubdomain, + subdomain: tunnelSubdomain, }; const port = config.get('port') as number; diff --git a/packages/core/src/Constants.ts b/packages/core/src/Constants.ts index 1596c0c737..a11b6d9402 100644 --- a/packages/core/src/Constants.ts +++ b/packages/core/src/Constants.ts @@ -5,3 +5,4 @@ export const EXTENSIONS_SUBDIRECTORY = 'custom'; export const USER_FOLDER_ENV_OVERWRITE = 'N8N_USER_FOLDER'; export const USER_SETTINGS_FILE_NAME = 'config'; export const USER_SETTINGS_SUBFOLDER = '.n8n'; +export const TUNNEL_SUBDOMAIN_ENV = 'N8N_TUNNEL_SUBDOMAIN';