From 24c3150056401ddcf49f7266897b6c73ccc06253 Mon Sep 17 00:00:00 2001 From: Yoshino-s Date: Mon, 29 Apr 2024 16:55:45 +0800 Subject: [PATCH] fix(core): Add `view engine` to webhook server to support forms (#9224) --- packages/cli/src/AbstractServer.ts | 7 ++++++- packages/cli/src/Server.ts | 14 +------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/AbstractServer.ts b/packages/cli/src/AbstractServer.ts index cf622863a6..9496b1dffc 100644 --- a/packages/cli/src/AbstractServer.ts +++ b/packages/cli/src/AbstractServer.ts @@ -2,11 +2,12 @@ import { Container, Service } from 'typedi'; import { readFile } from 'fs/promises'; import type { Server } from 'http'; import express from 'express'; +import { engine as expressHandlebars } from 'express-handlebars'; import compression from 'compression'; import isbot from 'isbot'; import config from '@/config'; -import { N8N_VERSION, inDevelopment, inTest } from '@/constants'; +import { N8N_VERSION, TEMPLATES_DIR, inDevelopment, inTest } from '@/constants'; import * as Db from '@/Db'; import { N8nInstanceType } from '@/Interfaces'; import { ExternalHooks } from '@/ExternalHooks'; @@ -62,6 +63,10 @@ export abstract class AbstractServer { this.app = express(); this.app.disable('x-powered-by'); + this.app.engine('handlebars', expressHandlebars({ defaultLayout: false })); + this.app.set('view engine', 'handlebars'); + this.app.set('views', TEMPLATES_DIR); + const proxyHops = config.getEnv('proxy_hops'); if (proxyHops > 0) this.app.set('trust proxy', proxyHops); diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index fe25646fbe..4b2f3ce194 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -10,7 +10,6 @@ import { promisify } from 'util'; import cookieParser from 'cookie-parser'; import express from 'express'; import helmet from 'helmet'; -import { engine as expressHandlebars } from 'express-handlebars'; import { type Class, InstanceSettings } from 'n8n-core'; import type { IN8nUISettings } from 'n8n-workflow'; @@ -21,14 +20,7 @@ import config from '@/config'; import { Queue } from '@/Queue'; import { WorkflowsController } from '@/workflows/workflows.controller'; -import { - EDITOR_UI_DIST_DIR, - inDevelopment, - inE2ETests, - N8N_VERSION, - TEMPLATES_DIR, - Time, -} from '@/constants'; +import { EDITOR_UI_DIST_DIR, inDevelopment, inE2ETests, N8N_VERSION, Time } from '@/constants'; import { CredentialsController } from '@/credentials/credentials.controller'; import type { APIRequest, CurlHelper } from '@/requests'; import { registerController } from '@/decorators'; @@ -95,10 +87,6 @@ export class Server extends AbstractServer { constructor() { super('main'); - this.app.engine('handlebars', expressHandlebars({ defaultLayout: false })); - this.app.set('view engine', 'handlebars'); - this.app.set('views', TEMPLATES_DIR); - this.testWebhooksEnabled = true; this.webhooksEnabled = !config.getEnv('endpoints.disableProductionWebhooksOnMainProcess'); }