mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Webhook Node): Setting to enable multiple outputs/methods (#9086)
Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
@@ -74,7 +74,60 @@ export class Webhook extends Node {
|
||||
credentials: credentialsProperty(this.authPropertyName),
|
||||
webhooks: [defaultWebhookDescription],
|
||||
properties: [
|
||||
httpMethodsProperty,
|
||||
{
|
||||
displayName: 'Allow Multiple HTTP Methods',
|
||||
name: 'multipleMethods',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
isNodeSetting: true,
|
||||
description: 'Whether to allow the webhook to listen for multiple HTTP methods',
|
||||
},
|
||||
{
|
||||
...httpMethodsProperty,
|
||||
displayOptions: {
|
||||
show: {
|
||||
multipleMethods: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'HTTP Methods',
|
||||
name: 'httpMethod',
|
||||
type: 'multiOptions',
|
||||
options: [
|
||||
{
|
||||
name: 'DELETE',
|
||||
value: 'DELETE',
|
||||
},
|
||||
{
|
||||
name: 'GET',
|
||||
value: 'GET',
|
||||
},
|
||||
{
|
||||
name: 'HEAD',
|
||||
value: 'HEAD',
|
||||
},
|
||||
{
|
||||
name: 'PATCH',
|
||||
value: 'PATCH',
|
||||
},
|
||||
{
|
||||
name: 'POST',
|
||||
value: 'POST',
|
||||
},
|
||||
{
|
||||
name: 'PUT',
|
||||
value: 'PUT',
|
||||
},
|
||||
],
|
||||
default: ['GET', 'POST'],
|
||||
description: 'The HTTP methods to listen to',
|
||||
displayOptions: {
|
||||
show: {
|
||||
multipleMethods: [true],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Path',
|
||||
name: 'path',
|
||||
@@ -144,6 +197,7 @@ export class Webhook extends Node {
|
||||
};
|
||||
const req = context.getRequestObject();
|
||||
const resp = context.getResponseObject();
|
||||
const requestMethod = context.getRequestObject().method;
|
||||
|
||||
if (!isIpWhitelisted(options.ipWhitelist, req.ips, req.ip)) {
|
||||
resp.writeHead(403);
|
||||
@@ -165,7 +219,7 @@ export class Webhook extends Node {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const prepareOutput = setupOutputConnection(context, {
|
||||
const prepareOutput = setupOutputConnection(context, requestMethod, {
|
||||
jwtPayload: validationData,
|
||||
});
|
||||
|
||||
|
||||
@@ -50,22 +50,34 @@ export const getResponseData = (parameters: WebhookParameters) => {
|
||||
};
|
||||
|
||||
export const configuredOutputs = (parameters: WebhookParameters) => {
|
||||
const httpMethod = parameters.httpMethod;
|
||||
const httpMethod = parameters.httpMethod as string | string[];
|
||||
|
||||
return [
|
||||
{
|
||||
if (!Array.isArray(httpMethod))
|
||||
return [
|
||||
{
|
||||
type: `${NodeConnectionType.Main}`,
|
||||
displayName: httpMethod,
|
||||
},
|
||||
];
|
||||
|
||||
const outputs = httpMethod.map((method) => {
|
||||
return {
|
||||
type: `${NodeConnectionType.Main}`,
|
||||
displayName: httpMethod,
|
||||
},
|
||||
];
|
||||
displayName: method,
|
||||
};
|
||||
});
|
||||
|
||||
return outputs;
|
||||
};
|
||||
|
||||
export const setupOutputConnection = (
|
||||
ctx: IWebhookFunctions,
|
||||
method: string,
|
||||
additionalData: {
|
||||
jwtPayload?: IDataObject;
|
||||
},
|
||||
) => {
|
||||
const httpMethod = ctx.getNodeParameter('httpMethod', []) as string[] | string;
|
||||
let webhookUrl = ctx.getNodeWebhookUrl('default') as string;
|
||||
const executionMode = ctx.getMode() === 'manual' ? 'test' : 'production';
|
||||
|
||||
@@ -73,13 +85,29 @@ export const setupOutputConnection = (
|
||||
webhookUrl = webhookUrl.replace('/webhook/', '/webhook-test/');
|
||||
}
|
||||
|
||||
// multi methods could be set in settings of node, so we need to check if it's an array
|
||||
if (!Array.isArray(httpMethod)) {
|
||||
return (outputData: INodeExecutionData): INodeExecutionData[][] => {
|
||||
outputData.json.webhookUrl = webhookUrl;
|
||||
outputData.json.executionMode = executionMode;
|
||||
if (additionalData?.jwtPayload) {
|
||||
outputData.json.jwtPayload = additionalData.jwtPayload;
|
||||
}
|
||||
return [[outputData]];
|
||||
};
|
||||
}
|
||||
|
||||
const outputIndex = httpMethod.indexOf(method.toUpperCase());
|
||||
const outputs: INodeExecutionData[][] = httpMethod.map(() => []);
|
||||
|
||||
return (outputData: INodeExecutionData): INodeExecutionData[][] => {
|
||||
outputData.json.webhookUrl = webhookUrl;
|
||||
outputData.json.executionMode = executionMode;
|
||||
if (additionalData?.jwtPayload) {
|
||||
outputData.json.jwtPayload = additionalData.jwtPayload;
|
||||
}
|
||||
return [[outputData]];
|
||||
outputs[outputIndex] = [outputData];
|
||||
return outputs;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user