diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index a72cb065c7..13fc5697ec 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -211,7 +211,7 @@ export class ActiveWorkflowRunner { */ async addWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflowExecuteAdditionalDataWorkflow, mode: WorkflowExecuteMode): Promise { const webhooks = WebhookHelpers.getWorkflowWebhooks(workflow, additionalData); - let path = ''; + let path = '' as string | undefined; for (const webhookData of webhooks) { @@ -221,12 +221,20 @@ export class ActiveWorkflowRunner { path = node.parameters.path as string; if (node.parameters.path === undefined) { - path = workflow.getSimpleParameterValue(node, webhookData.webhookDescription['path'], 'GET') as string; + path = workflow.getSimpleParameterValue(node, webhookData.webhookDescription['path']) as string | undefined; + + if (path === undefined) { + // TODO: Use a proper logger + console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflow.id}".`); + continue; + } } + const isFullPath: boolean = workflow.getSimpleParameterValue(node, webhookData.webhookDescription['isFullPath'], false) as boolean; + const webhook = { workflowId: webhookData.workflowId, - webhookPath: NodeHelpers.getNodeWebhookPath(workflow.id as string, node, path), + webhookPath: NodeHelpers.getNodeWebhookPath(workflow.id as string, node, path, isFullPath), node: node.name, method: webhookData.httpMethod, } as IWebhookDb; @@ -257,7 +265,7 @@ export class ActiveWorkflowRunner { // it's a error runnig the webhook methods (checkExists, create) errorMessage = error.detail; } else { - errorMessage = error; + errorMessage = error.message; } throw new Error(errorMessage); diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 4e27568983..cf53b85665 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -46,7 +46,6 @@ import { WorkflowCredentials, WebhookHelpers, WorkflowExecuteAdditionalData, - WorkflowHelpers, WorkflowRunner, GenericHelpers, } from './'; diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 640a75ca9a..9cc9c776de 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -289,7 +289,8 @@ export function getNodeWebhookUrl(name: string, workflow: Workflow, node: INode, return undefined; } - return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString()); + const isFullPath: boolean = workflow.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean; + return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString(), isFullPath); } diff --git a/packages/editor-ui/src/components/NodeWebhooks.vue b/packages/editor-ui/src/components/NodeWebhooks.vue index b649575a0b..e2875a49fd 100644 --- a/packages/editor-ui/src/components/NodeWebhooks.vue +++ b/packages/editor-ui/src/components/NodeWebhooks.vue @@ -110,8 +110,9 @@ export default mixins( const workflowId = this.$store.getters.workflowId; const path = this.getValue(webhookData, 'path'); + const isFullPath = this.getValue(webhookData, 'isFullPath') as unknown as boolean || false; - return NodeHelpers.getNodeWebhookUrl(baseUrl, workflowId, this.node, path); + return NodeHelpers.getNodeWebhookUrl(baseUrl, workflowId, this.node, path, isFullPath); }, }, watch: { diff --git a/packages/nodes-base/nodes/Webhook.node.ts b/packages/nodes-base/nodes/Webhook.node.ts index 26562abc4c..1778d44290 100644 --- a/packages/nodes-base/nodes/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook.node.ts @@ -77,6 +77,7 @@ export class Webhook implements INodeType { { name: 'default', httpMethod: '={{$parameter["httpMethod"]}}', + isFullPath: true, responseCode: '={{$parameter["responseCode"]}}', responseMode: '={{$parameter["responseMode"]}}', responseData: '={{$parameter["responseData"]}}', diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index b5f143e3f6..32f272f25c 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -520,8 +520,9 @@ export interface IWebhookData { } export interface IWebhookDescription { - [key: string]: WebhookHttpMethod | WebhookResponseMode | string | undefined; + [key: string]: WebhookHttpMethod | WebhookResponseMode | boolean | string | undefined; httpMethod: WebhookHttpMethod | string; + isFullPath?: boolean; name: string; path: string; responseBinaryPropertyName?: string; diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 87e219699d..610aefda56 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -755,7 +755,7 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: const returnData: IWebhookData[] = []; for (const webhookDescription of nodeType.description.webhooks) { - let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path'], 'GET'); + let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path']); if (nodeWebhookPath === undefined) { // TODO: Use a proper logger console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); @@ -768,7 +768,8 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: nodeWebhookPath = nodeWebhookPath.slice(1); } - const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath); + const isFullPath: boolean = workflow.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean; + const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath); const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET'); @@ -808,7 +809,7 @@ export function getNodeWebhooksBasic(workflow: Workflow, node: INode): IWebhookD const returnData: IWebhookData[] = []; for (const webhookDescription of nodeType.description.webhooks) { - let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path'], 'GET'); + let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path']); if (nodeWebhookPath === undefined) { // TODO: Use a proper logger console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); @@ -821,9 +822,11 @@ export function getNodeWebhooksBasic(workflow: Workflow, node: INode): IWebhookD nodeWebhookPath = nodeWebhookPath.slice(1); } - const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath); + const isFullPath: boolean = workflow.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean; - const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET'); + const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath); + + const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod']); if (httpMethod === undefined) { // TODO: Use a proper logger @@ -854,12 +857,12 @@ export function getNodeWebhooksBasic(workflow: Workflow, node: INode): IWebhookD * @param {string} path * @returns {string} */ -export function getNodeWebhookPath(workflowId: string, node: INode, path: string): string { +export function getNodeWebhookPath(workflowId: string, node: INode, path: string, isFullPath?: boolean): string { let webhookPath = ''; if (node.webhookPath === undefined) { webhookPath = `${workflowId}/${encodeURIComponent(node.name.toLowerCase())}/${path}`; } else { - if (node.type === 'n8n-nodes-base.webhook') { + if (isFullPath === true) { return path; } webhookPath = `${node.webhookPath}/${path}`; @@ -876,11 +879,11 @@ export function getNodeWebhookPath(workflowId: string, node: INode, path: string * @param {string} workflowId * @param {string} nodeTypeName * @param {string} path + * @param {boolean} isFullPath * @returns {string} */ -export function getNodeWebhookUrl(baseUrl: string, workflowId: string, node: INode, path: string): string { - // return `${baseUrl}/${workflowId}/${nodeTypeName}/${path}`; - return `${baseUrl}/${getNodeWebhookPath(workflowId, node, path)}`; +export function getNodeWebhookUrl(baseUrl: string, workflowId: string, node: INode, path: string, isFullPath?: boolean): string { + return `${baseUrl}/${getNodeWebhookPath(workflowId, node, path, isFullPath)}`; } diff --git a/packages/workflow/src/Workflow.ts b/packages/workflow/src/Workflow.ts index 9a7d3ef1eb..8d09738598 100644 --- a/packages/workflow/src/Workflow.ts +++ b/packages/workflow/src/Workflow.ts @@ -715,7 +715,7 @@ export class Workflow { * @returns {(string | undefined)} * @memberof Workflow */ - getSimpleParameterValue(node: INode, parameterValue: string | undefined, defaultValue?: boolean | number | string): boolean | number | string | undefined { + getSimpleParameterValue(node: INode, parameterValue: string | boolean | undefined, defaultValue?: boolean | number | string): boolean | number | string | undefined { if (parameterValue === undefined) { // Value is not set so return the default return defaultValue;