Make it possible to set tunnel subdomain via environment variable

This commit is contained in:
Jan Oberhauser 2019-10-15 07:21:15 +02:00
parent 92669bb77a
commit 369e8084d3
2 changed files with 12 additions and 3 deletions

View file

@ -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;

View file

@ -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';