From f1bb1f10f3aba55a5d5ed50fc25d8f53e43cb348 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Sat, 21 Dec 2019 15:36:08 -0500 Subject: [PATCH] changes --- packages/nodes-base/nodes/Webhook.node.ts | 58 ++++++++++++++++++----- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/packages/nodes-base/nodes/Webhook.node.ts b/packages/nodes-base/nodes/Webhook.node.ts index 3ac8acc3a2..da3ecd3cdb 100644 --- a/packages/nodes-base/nodes/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook.node.ts @@ -119,7 +119,6 @@ export class Webhook implements INodeType { default: 'GET', description: 'The HTTP method to liste to.', }, - { displayName: 'Path', name: 'path', @@ -205,7 +204,6 @@ export class Webhook implements INodeType { }, description: 'Name of the binary property to return', }, - { displayName: 'Options', name: 'options', @@ -238,15 +236,45 @@ export class Webhook implements INodeType { default: 'data', description: 'Name of the property to return the data of instead of the whole JSON.', }, + { + displayName: 'Raw Body', + name: 'rawBody', + type: 'boolean', + default: false, + description: 'Raw body (binary)', + }, + ], + }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + displayOptions: { + show: { + responseMode: [ + 'onReceived', + ], + }, + }, + placeholder: 'Add Option', + default: {}, + options: [ + { + displayName: 'Raw Body', + name: 'rawBody', + type: 'boolean', + default: false, + description: 'Raw body (binary)', + }, ], }, - ], }; async webhook(this: IWebhookFunctions): Promise { const authentication = this.getNodeParameter('authentication', 0) as string; + const options = this.getNodeParameter('options', 0) as string; const req = this.getRequestObject(); const resp = this.getResponseObject(); const headers = this.getHeaderData(); @@ -288,21 +316,27 @@ export class Webhook implements INodeType { return authorizationError(resp, realm, 403); } } - - const returnData: IDataObject[] = []; - - returnData.push( - { + const response = { + json: { body: this.getBodyData(), headers, query: this.getQueryData(), + }, + }; + // @ts-ignore + if (options.rawBody) { + // @ts-ignore + response.binary = { // @ts-ignore - rawBody: req.rawBody, - } - ); + data: req.rawBody.toString('base64'), + }; + } + return { workflowData: [ - this.helpers.returnJsonArray(returnData) + [ + response, + ], ], }; }