diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index fea2828941..6f35bd51b4 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -304,6 +304,7 @@ export interface IPushDataTestWebhook { export interface IResponseCallbackData { data?: IDataObject | IDataObject[]; noWebhookResponse?: boolean; + responseCode?: number; } diff --git a/packages/cli/src/ResponseHelper.ts b/packages/cli/src/ResponseHelper.ts index 73fd28235c..4d58f762a1 100644 --- a/packages/cli/src/ResponseHelper.ts +++ b/packages/cli/src/ResponseHelper.ts @@ -53,9 +53,13 @@ export function basicAuthAuthorizationError(resp: Response, realm: string, messa } -export function sendSuccessResponse(res: Response, data: any, raw?: boolean) { // tslint:disable-line:no-any +export function sendSuccessResponse(res: Response, data: any, raw?: boolean, responseCode?: number) { // tslint:disable-line:no-any res.setHeader('Content-Type', 'application/json'); + if (responseCode !== undefined) { + res.status(responseCode); + } + if (raw === true) { res.send(JSON.stringify(data)); return; diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index d44ebbc2c5..9704a936f2 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -1019,7 +1019,7 @@ class App { return; } - ResponseHelper.sendSuccessResponse(res, response.data, true); + ResponseHelper.sendSuccessResponse(res, response.data, true, response.responseCode); }); @@ -1043,7 +1043,7 @@ class App { return; } - ResponseHelper.sendSuccessResponse(res, response.data, true); + ResponseHelper.sendSuccessResponse(res, response.data, true, response.responseCode); }); @@ -1067,7 +1067,7 @@ class App { return; } - ResponseHelper.sendSuccessResponse(res, response.data, true); + ResponseHelper.sendSuccessResponse(res, response.data, true, response.responseCode); }); @@ -1091,7 +1091,7 @@ class App { return; } - ResponseHelper.sendSuccessResponse(res, response.data, true); + ResponseHelper.sendSuccessResponse(res, response.data, true, response.responseCode); }); diff --git a/packages/cli/src/WebhookHelpers.ts b/packages/cli/src/WebhookHelpers.ts index a4faa368ff..26dcd73724 100644 --- a/packages/cli/src/WebhookHelpers.ts +++ b/packages/cli/src/WebhookHelpers.ts @@ -115,6 +115,7 @@ export function getWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflo // Get the responseMode const reponseMode = webhookData.workflow.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['reponseMode'], 'onReceived'); + const responseCode = webhookData.workflow.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseCode'], 200); if (!['onReceived', 'lastNode'].includes(reponseMode as string)) { // If the mode is not known we error. Is probably best like that instead of using @@ -152,7 +153,8 @@ export function getWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflo if (webhookResultData.webhookResponse !== undefined) { // Data to respond with is given responseCallback(null, { - data: webhookResultData.webhookResponse + data: webhookResultData.webhookResponse, + responseCode, }); } else { // Send default response @@ -160,6 +162,7 @@ export function getWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflo data: { message: 'Webhook call got received.', }, + responseCode, }); } return; @@ -173,12 +176,16 @@ export function getWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflo // Data to respond with is given responseCallback(null, { data: webhookResultData.webhookResponse, + responseCode, }); } else { + console.log('k1: ' + responseCode); + responseCallback(null, { data: { message: 'Workflow got started.', - } + }, + responseCode, }); } @@ -229,7 +236,8 @@ export function getWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflo responseCallback(null, { data: { message: 'Workflow did execute sucessfully but no data got returned.', - } + }, + responseCode, }); didSendResponse = true; } @@ -242,7 +250,8 @@ export function getWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflo responseCallback(null, { data: { message: 'Workflow did execute sucessfully but the last node did not return any data.', - } + }, + responseCode, }); } didSendResponse = true; @@ -302,6 +311,7 @@ export function getWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflo responseCallback(null, { data, + responseCode, }); } didSendResponse = true; diff --git a/packages/nodes-base/nodes/Webhook.node.ts b/packages/nodes-base/nodes/Webhook.node.ts index 58ed435f27..2e17eb97c2 100644 --- a/packages/nodes-base/nodes/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook.node.ts @@ -71,6 +71,7 @@ export class Webhook implements INodeType { { name: 'default', httpMethod: '={{$parameter["httpMethod"]}}', + responseCode: '={{$parameter["responseCode"]}}', reponseMode: '={{$parameter["reponseMode"]}}', reponseData: '={{$parameter["reponseData"]}}', responseBinaryPropertyName: '={{$parameter["responseBinaryPropertyName"]}}', @@ -122,10 +123,21 @@ export class Webhook implements INodeType { name: 'path', type: 'string', default: '', - placeholder: '', + placeholder: 'webhook', required: true, description: 'The path to listen to', }, + { + displayName: 'Response Code', + name: 'responseCode', + type: 'number', + typeOptions: { + minValue: 100, + maxValue: 599, + }, + default: 200, + description: 'The HTTP Response code to return', + }, { displayName: 'Reponse Mode', name: 'reponseMode', @@ -134,7 +146,7 @@ export class Webhook implements INodeType { { name: 'On Received', value: 'onReceived', - description: 'Returns directly with Reponse Code 200', + description: 'Returns directly with defined Response Code', }, { name: 'Last Node',