fix(core): Ensure nodes post-processors run in the correct order (#7500)

Fixes #7497
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-10-25 13:59:38 +02:00 committed by GitHub
parent c47d27dd6d
commit 6f45298d3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 37 deletions

View file

@ -123,7 +123,7 @@ import { toHttpNodeParameters } from '@/CurlConverterHelper';
import { EventBusController } from '@/eventbus/eventBus.controller'; import { EventBusController } from '@/eventbus/eventBus.controller';
import { EventBusControllerEE } from '@/eventbus/eventBus.controller.ee'; import { EventBusControllerEE } from '@/eventbus/eventBus.controller.ee';
import { licenseController } from './license/license.controller'; import { licenseController } from './license/license.controller';
import { Push, setupPushServer, setupPushHandler } from '@/push'; import { setupPushServer, setupPushHandler } from '@/push';
import { setupAuthMiddlewares } from './middlewares'; import { setupAuthMiddlewares } from './middlewares';
import { handleLdapInit, isLdapEnabled } from './Ldap/helpers'; import { handleLdapInit, isLdapEnabled } from './Ldap/helpers';
import { AbstractServer } from './AbstractServer'; import { AbstractServer } from './AbstractServer';
@ -171,12 +171,10 @@ export class Server extends AbstractServer {
private credentialTypes: ICredentialTypes; private credentialTypes: ICredentialTypes;
private frontendService: FrontendService; private frontendService?: FrontendService;
private postHog: PostHogClient; private postHog: PostHogClient;
private push: Push;
constructor() { constructor() {
super('main'); super('main');
@ -194,13 +192,8 @@ export class Server extends AbstractServer {
this.nodeTypes = Container.get(NodeTypes); this.nodeTypes = Container.get(NodeTypes);
if (!config.getEnv('endpoints.disableUi')) { if (!config.getEnv('endpoints.disableUi')) {
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/no-var-requires
const { FrontendService } = await import('@/services/frontend.service'); this.frontendService = Container.get(require('@/services/frontend.service').FrontendService);
this.frontendService = Container.get(FrontendService);
this.loadNodesAndCredentials.addPostProcessor(async () =>
this.frontendService.generateTypes(),
);
await this.frontendService.generateTypes();
} }
this.activeExecutionsInstance = Container.get(ActiveExecutions); this.activeExecutionsInstance = Container.get(ActiveExecutions);
@ -210,8 +203,6 @@ export class Server extends AbstractServer {
this.presetCredentialsLoaded = false; this.presetCredentialsLoaded = false;
this.endpointPresetCredentials = config.getEnv('credentials.overwrite.endpoint'); this.endpointPresetCredentials = config.getEnv('credentials.overwrite.endpoint');
this.push = Container.get(Push);
await super.start(); await super.start();
LoggerProxy.debug(`Server ID: ${this.uniqueInstanceId}`); LoggerProxy.debug(`Server ID: ${this.uniqueInstanceId}`);
@ -372,14 +363,17 @@ export class Server extends AbstractServer {
await Container.get(MetricsService).configureMetrics(this.app); await Container.get(MetricsService).configureMetrics(this.app);
} }
this.frontendService.addToSettings({ const { frontendService } = this;
isNpmAvailable: await exec('npm --version') if (frontendService) {
.then(() => true) frontendService.addToSettings({
.catch(() => false), isNpmAvailable: await exec('npm --version')
versionCli: N8N_VERSION, .then(() => true)
}); .catch(() => false),
versionCli: N8N_VERSION,
});
await this.externalHooks.run('frontend.settings', [this.frontendService.getSettings()]); await this.externalHooks.run('frontend.settings', [frontendService.getSettings()]);
}
await this.postHog.init(); await this.postHog.init();
@ -408,7 +402,9 @@ export class Server extends AbstractServer {
if (isApiEnabled()) { if (isApiEnabled()) {
const { apiRouters, apiLatestVersion } = await loadPublicApiVersions(publicApiEndpoint); const { apiRouters, apiLatestVersion } = await loadPublicApiVersions(publicApiEndpoint);
this.app.use(...apiRouters); this.app.use(...apiRouters);
this.frontendService.settings.publicApi.latestVersion = apiLatestVersion; if (frontendService) {
frontendService.settings.publicApi.latestVersion = apiLatestVersion;
}
} }
// Parse cookies for easier access // Parse cookies for easier access
this.app.use(cookieParser()); this.app.use(cookieParser());
@ -1187,17 +1183,21 @@ export class Server extends AbstractServer {
// Settings // Settings
// ---------------------------------------- // ----------------------------------------
// Returns the current settings for the UI if (frontendService) {
this.app.get( // Returns the current settings for the UI
`/${this.restEndpoint}/settings`, this.app.get(
ResponseHelper.send( `/${this.restEndpoint}/settings`,
async (req: express.Request, res: express.Response): Promise<IN8nUISettings> => { ResponseHelper.send(
void Container.get(InternalHooks).onFrontendSettingsAPI(req.headers.sessionid as string); async (req: express.Request, res: express.Response): Promise<IN8nUISettings> => {
void Container.get(InternalHooks).onFrontendSettingsAPI(
req.headers.sessionid as string,
);
return this.frontendService.getSettings(); return frontendService.getSettings();
}, },
), ),
); );
}
// ---------------------------------------- // ----------------------------------------
// EventBus Setup // EventBus Setup
@ -1227,7 +1227,7 @@ export class Server extends AbstractServer {
Container.get(CredentialsOverwrites).setData(body); Container.get(CredentialsOverwrites).setData(body);
await this.frontendService?.generateTypes(); await frontendService?.generateTypes();
this.presetCredentialsLoaded = true; this.presetCredentialsLoaded = true;
@ -1239,7 +1239,7 @@ export class Server extends AbstractServer {
); );
} }
if (!config.getEnv('endpoints.disableUi')) { if (frontendService) {
const staticOptions: ServeStaticOptions = { const staticOptions: ServeStaticOptions = {
cacheControl: false, cacheControl: false,
setHeaders: (res: express.Response, path: string) => { setHeaders: (res: express.Response, path: string) => {

View file

@ -107,10 +107,8 @@ class WorkflowRunnerProcess {
// Init db since we need to read the license. // Init db since we need to read the license.
await Db.init(); await Db.init();
const loadNodesAndCredentials = Container.get(LoadNodesAndCredentials);
await loadNodesAndCredentials.init();
const nodeTypes = Container.get(NodeTypes); const nodeTypes = Container.get(NodeTypes);
await Container.get(LoadNodesAndCredentials).init();
// Load all external hooks // Load all external hooks
const externalHooks = Container.get(ExternalHooks); const externalHooks = Container.get(ExternalHooks);

View file

@ -47,8 +47,8 @@ export abstract class BaseCommand extends Command {
// Make sure the settings exist // Make sure the settings exist
this.instanceSettings = Container.get(InstanceSettings); this.instanceSettings = Container.get(InstanceSettings);
await Container.get(LoadNodesAndCredentials).init();
this.nodeTypes = Container.get(NodeTypes); this.nodeTypes = Container.get(NodeTypes);
await Container.get(LoadNodesAndCredentials).init();
await Db.init().catch(async (error: Error) => await Db.init().catch(async (error: Error) =>
this.exitWithCrash('There was an error initializing DB', error), this.exitWithCrash('There was an error initializing DB', error),

View file

@ -46,6 +46,9 @@ export class FrontendService {
private readonly mailer: UserManagementMailer, private readonly mailer: UserManagementMailer,
private readonly instanceSettings: InstanceSettings, private readonly instanceSettings: InstanceSettings,
) { ) {
loadNodesAndCredentials.addPostProcessor(async () => this.generateTypes());
void this.generateTypes();
this.initSettings(); this.initSettings();
if (config.getEnv('nodes.communityPackages.enabled')) { if (config.getEnv('nodes.communityPackages.enabled')) {