mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
refactor(core): Port some legacy top-level schema keys (#16636)
This commit is contained in:
@@ -178,4 +178,16 @@ export class GlobalConfig {
|
||||
/** Number of reverse proxies n8n is running behind. */
|
||||
@Env('N8N_PROXY_HOPS')
|
||||
proxy_hops: number = 0;
|
||||
|
||||
/** SSL key for HTTPS protocol. */
|
||||
@Env('N8N_SSL_KEY')
|
||||
ssl_key: string = '';
|
||||
|
||||
/** SSL cert for HTTPS protocol. */
|
||||
@Env('N8N_SSL_CERT')
|
||||
ssl_cert: string = '';
|
||||
|
||||
/** Public URL where the editor is accessible. Also used for emails sent from n8n. */
|
||||
@Env('N8N_EDITOR_BASE_URL')
|
||||
editorBaseUrl: string = '';
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ describe('GlobalConfig', () => {
|
||||
enabled: true,
|
||||
},
|
||||
proxy_hops: 0,
|
||||
ssl_key: '',
|
||||
ssl_cert: '',
|
||||
editorBaseUrl: '',
|
||||
database: {
|
||||
logging: {
|
||||
enabled: false,
|
||||
|
||||
@@ -75,8 +75,8 @@ export abstract class AbstractServer {
|
||||
const proxyHops = this.globalConfig.proxy_hops;
|
||||
if (proxyHops > 0) this.app.set('trust proxy', proxyHops);
|
||||
|
||||
this.sslKey = config.getEnv('ssl_key');
|
||||
this.sslCert = config.getEnv('ssl_cert');
|
||||
this.sslKey = this.globalConfig.ssl_key;
|
||||
this.sslCert = this.globalConfig.ssl_cert;
|
||||
|
||||
const { endpoints } = this.globalConfig;
|
||||
this.restEndpoint = endpoints.rest;
|
||||
|
||||
@@ -102,25 +102,6 @@ export const schema = {
|
||||
},
|
||||
},
|
||||
|
||||
ssl_key: {
|
||||
format: String,
|
||||
default: '',
|
||||
env: 'N8N_SSL_KEY',
|
||||
doc: 'SSL Key for HTTPS Protocol',
|
||||
},
|
||||
ssl_cert: {
|
||||
format: String,
|
||||
default: '',
|
||||
env: 'N8N_SSL_CERT',
|
||||
doc: 'SSL Cert for HTTPS Protocol',
|
||||
},
|
||||
editorBaseUrl: {
|
||||
format: String,
|
||||
default: '',
|
||||
env: 'N8N_EDITOR_BASE_URL',
|
||||
doc: 'Public URL where the editor is accessible. Also used for emails sent from n8n.',
|
||||
},
|
||||
|
||||
userManagement: {
|
||||
jwtSecret: {
|
||||
doc: 'Set a specific JWT secret (optional - n8n can generate one)', // Generated @ start.ts
|
||||
|
||||
@@ -1,42 +1,51 @@
|
||||
import type { GlobalConfig } from '@n8n/config';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
import { UrlService } from '../url.service';
|
||||
|
||||
describe('UrlService', () => {
|
||||
beforeEach(() => {
|
||||
process.env.WEBHOOK_URL = undefined;
|
||||
config.load(config.default);
|
||||
});
|
||||
|
||||
describe('getInstanceBaseUrl', () => {
|
||||
it('should set URL from N8N_EDITOR_BASE_URL', () => {
|
||||
config.set('editorBaseUrl', 'https://example.com/');
|
||||
process.env.WEBHOOK_URL = undefined;
|
||||
const urlService = new UrlService(mock<GlobalConfig>());
|
||||
const urlService = new UrlService(
|
||||
mock<GlobalConfig>({
|
||||
editorBaseUrl: 'https://example.com/',
|
||||
}),
|
||||
);
|
||||
expect(urlService.getInstanceBaseUrl()).toBe('https://example.com');
|
||||
});
|
||||
|
||||
it('should set URL from WEBHOOK_URL', () => {
|
||||
config.set('editorBaseUrl', '');
|
||||
process.env.WEBHOOK_URL = 'https://example.com/';
|
||||
const urlService = new UrlService(mock<GlobalConfig>());
|
||||
const urlService = new UrlService(
|
||||
mock<GlobalConfig>({
|
||||
editorBaseUrl: '',
|
||||
}),
|
||||
);
|
||||
expect(urlService.getInstanceBaseUrl()).toBe('https://example.com');
|
||||
});
|
||||
|
||||
it('should trim quotes when setting URL from N8N_EDITOR_BASE_URL', () => {
|
||||
config.set('editorBaseUrl', '"https://example.com"');
|
||||
process.env.WEBHOOK_URL = undefined;
|
||||
const urlService = new UrlService(mock<GlobalConfig>());
|
||||
const urlService = new UrlService(
|
||||
mock<GlobalConfig>({
|
||||
editorBaseUrl: '"https://example.com"',
|
||||
}),
|
||||
);
|
||||
expect(urlService.getInstanceBaseUrl()).toBe('https://example.com');
|
||||
});
|
||||
|
||||
it('should trim quotes when setting URL from WEBHOOK_URL', () => {
|
||||
config.set('editorBaseUrl', '');
|
||||
process.env.WEBHOOK_URL = '"https://example.com/"';
|
||||
const urlService = new UrlService(mock<GlobalConfig>());
|
||||
const urlService = new UrlService(
|
||||
mock<GlobalConfig>({
|
||||
editorBaseUrl: '',
|
||||
}),
|
||||
);
|
||||
expect(urlService.getInstanceBaseUrl()).toBe('https://example.com');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ describe('UserService', () => {
|
||||
port: 5678,
|
||||
listen_address: '::',
|
||||
protocol: 'http',
|
||||
editorBaseUrl: '',
|
||||
});
|
||||
const urlService = new UrlService(globalConfig);
|
||||
const userRepository = mockInstance(UserRepository);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { Service } from '@n8n/di';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
@Service()
|
||||
export class UrlService {
|
||||
/** Returns the base URL n8n is reachable from */
|
||||
@@ -23,7 +21,7 @@ export class UrlService {
|
||||
|
||||
/** Return the n8n instance base URL without trailing slash */
|
||||
getInstanceBaseUrl(): string {
|
||||
const n8nBaseUrl = this.trimQuotes(config.getEnv('editorBaseUrl')) || this.getWebhookBaseUrl();
|
||||
const n8nBaseUrl = this.trimQuotes(this.globalConfig.editorBaseUrl) || this.getWebhookBaseUrl();
|
||||
|
||||
return n8nBaseUrl.endsWith('/') ? n8nBaseUrl.slice(0, n8nBaseUrl.length - 1) : n8nBaseUrl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user