Expose public api activation to the settings

This commit is contained in:
ricardo 2022-04-28 12:06:22 -04:00
parent 20087373b9
commit f762e143c3
4 changed files with 13 additions and 6 deletions

View file

@ -576,11 +576,11 @@ export const schema = {
}, },
}, },
publicApiEndpoints: { publicApi: {
disable: { disabled: {
format: Boolean, format: Boolean,
default: false, default: false,
env: 'N8N_PUBLIC_API_DISABLE', env: 'N8N_PUBLIC_API_DISABLED',
doc: 'Whether to disable the Public API', doc: 'Whether to disable the Public API',
}, },
path: { path: {

View file

@ -457,6 +457,7 @@ export interface IN8nUISettings {
personalizationSurveyEnabled: boolean; personalizationSurveyEnabled: boolean;
defaultLocale: string; defaultLocale: string;
userManagement: IUserManagementSettings; userManagement: IUserManagementSettings;
publicApi: IPublicApiSettings;
workflowTagsDisabled: boolean; workflowTagsDisabled: boolean;
logLevel: 'info' | 'debug' | 'warn' | 'error' | 'verbose' | 'silent'; logLevel: 'info' | 'debug' | 'warn' | 'error' | 'verbose' | 'silent';
hiringBannerEnabled: boolean; hiringBannerEnabled: boolean;
@ -480,6 +481,9 @@ export interface IUserManagementSettings {
showSetupOnFirstLoad?: boolean; showSetupOnFirstLoad?: boolean;
smtpSetup: boolean; smtpSetup: boolean;
} }
export interface IPublicApiSettings {
enabled: boolean;
}
export interface IPackageVersions { export interface IPackageVersions {
cli: string; cli: string;

View file

@ -253,7 +253,7 @@ class App {
this.payloadSizeMax = config.get('endpoints.payloadSizeMax'); this.payloadSizeMax = config.get('endpoints.payloadSizeMax');
this.timezone = config.get('generic.timezone'); this.timezone = config.get('generic.timezone');
this.restEndpoint = config.get('endpoints.rest'); this.restEndpoint = config.get('endpoints.rest');
this.publicApiEndpoint = config.get('publicApiEndpoints.path'); this.publicApiEndpoint = config.get('publicApi.path');
this.activeWorkflowRunner = ActiveWorkflowRunner.getInstance(); this.activeWorkflowRunner = ActiveWorkflowRunner.getInstance();
this.testWebhooks = TestWebhooks.getInstance(); this.testWebhooks = TestWebhooks.getInstance();
@ -324,6 +324,9 @@ class App {
config.getEnv('userManagement.skipInstanceOwnerSetup') === false, config.getEnv('userManagement.skipInstanceOwnerSetup') === false,
smtpSetup: isEmailSetUp(), smtpSetup: isEmailSetUp(),
}, },
publicApi: {
enabled: config.getEnv('publicApi.disabled') === false,
},
workflowTagsDisabled: config.getEnv('workflowTagsDisabled'), workflowTagsDisabled: config.getEnv('workflowTagsDisabled'),
logLevel: config.getEnv('logs.level'), logLevel: config.getEnv('logs.level'),
hiringBannerEnabled: config.getEnv('hiringBanner.enabled'), hiringBannerEnabled: config.getEnv('hiringBanner.enabled'),
@ -581,7 +584,7 @@ class App {
return ResponseHelper.sendSuccessResponse(res, {}, true, 204); return ResponseHelper.sendSuccessResponse(res, {}, true, 204);
}); });
if (!config.getEnv('publicApiEndpoints.disable')) { if (!config.getEnv('publicApi.disabled')) {
this.app.use(`/${this.publicApiEndpoint}`, ...(await loadPublicApiVersions())); this.app.use(`/${this.publicApiEndpoint}`, ...(await loadPublicApiVersions()));
} }
// Parse cookies for easier access // Parse cookies for easier access

View file

@ -2,7 +2,7 @@ import config from '../../../config';
export const REST_PATH_SEGMENT = config.getEnv('endpoints.rest') as Readonly<string>; export const REST_PATH_SEGMENT = config.getEnv('endpoints.rest') as Readonly<string>;
export const PUBLIC_API_REST_PATH_SEGMENT = config.get('publicApiEndpoints.path') as Readonly<string>; export const PUBLIC_API_REST_PATH_SEGMENT = config.getEnv('publicApi.path') as Readonly<string>;
export const AUTHLESS_ENDPOINTS: Readonly<string[]> = [ export const AUTHLESS_ENDPOINTS: Readonly<string[]> = [
'healthz', 'healthz',