diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index 3e6fe50cb4..8b7bc0aff5 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -161,21 +161,18 @@ export class ActiveWorkflowRunner { }); } -/** - * Gets all request methods associated with a single webhook - * @param path webhook path - */ + /** + * Gets all request methods associated with a single webhook + * + * @param {string} path webhook path + * @returns {Promise} + * @memberof ActiveWorkflowRunner + */ async getWebhookMethods(path: string) : Promise { const webhooks = await Db.collections.Webhook?.find({ webhookPath: path}) as IWebhookDb[]; - // check if something exist - if (webhooks === undefined) { - // The requested webhooks are not registered - throw new ResponseHelper.ResponseError(`The requested webhook "${path}" is not registered.`, 404, 404); - } - // Gather all request methods in string array - let webhookMethods : string[] = webhooks.map(webhook => webhook.method); + const webhookMethods: string[] = webhooks.map(webhook => webhook.method); return webhookMethods; } diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index da8c7b602e..1791682f99 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -1572,10 +1572,11 @@ class App { // Cut away the "/webhook/" to get the registred part of the url const requestUrl = (req as ICustomRequest).parsedUrl!.pathname!.slice(this.endpointWebhook.length + 2); - let allowedMethods; + let allowedMethods: string[]; try { allowedMethods = await this.activeWorkflowRunner.getWebhookMethods(requestUrl); - + allowedMethods.push('OPTIONS'); + // Add custom "Allow" header to satisfy OPTIONS response. res.append('Allow', allowedMethods); } catch (error) { @@ -1654,9 +1655,10 @@ class App { // Cut away the "/webhook-test/" to get the registred part of the url const requestUrl = (req as ICustomRequest).parsedUrl!.pathname!.slice(this.endpointWebhookTest.length + 2); - let allowedMethods; + let allowedMethods: string[]; try { allowedMethods = await this.testWebhooks.getWebhookMethods(requestUrl); + allowedMethods.push('OPTIONS'); // Add custom "Allow" header to satisfy OPTIONS response. res.append('Allow', allowedMethods); diff --git a/packages/core/src/ActiveWebhooks.ts b/packages/core/src/ActiveWebhooks.ts index 0e4ea24434..69bc731b08 100644 --- a/packages/core/src/ActiveWebhooks.ts +++ b/packages/core/src/ActiveWebhooks.ts @@ -87,10 +87,10 @@ export class ActiveWebhooks { /** * Gets all request methods associated with a single webhook - * @param path + * @param path */ getWebhookMethods(path: string): string[] { - let methods : string[] = []; + const methods : string[] = []; Object.keys(this.webhookUrls) .filter(key => key.includes(path))