1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-11-10 12:35:46 +03:00

Make it use of full webhook path more generic

This commit is contained in:
Jan Oberhauser 2020-06-10 15:39:15 +02:00
parent 1f4b8f8999
commit 5ed86670a8
8 changed files with 33 additions and 19 deletions

View File

@ -211,7 +211,7 @@ export class ActiveWorkflowRunner {
*/
async addWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflowExecuteAdditionalDataWorkflow, mode: WorkflowExecuteMode): Promise<void> {
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);

View File

@ -46,7 +46,6 @@ import {
WorkflowCredentials,
WebhookHelpers,
WorkflowExecuteAdditionalData,
WorkflowHelpers,
WorkflowRunner,
GenericHelpers,
} from './';

View File

@ -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);
}

View File

@ -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: {

View File

@ -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"]}}',

View File

@ -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;

View File

@ -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)}`;
}

View File

@ -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;