diff --git a/packages/cli/src/webhooks/waiting-forms.ts b/packages/cli/src/webhooks/waiting-forms.ts index b6fec68ffa..5a491c1fb3 100644 --- a/packages/cli/src/webhooks/waiting-forms.ts +++ b/packages/cli/src/webhooks/waiting-forms.ts @@ -1,5 +1,6 @@ +import axios from 'axios'; import type express from 'express'; -import { FORM_NODE_TYPE, Workflow } from 'n8n-workflow'; +import { FORM_NODE_TYPE, sleep, Workflow } from 'n8n-workflow'; import { Service } from 'typedi'; import { ConflictError } from '@/errors/response-errors/conflict.error'; @@ -37,6 +38,25 @@ export class WaitingForms extends WaitingWebhooks { }); } + private async reloadForm(req: WaitingWebhookRequest, res: express.Response) { + try { + await sleep(1000); + + const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`; + const page = await axios({ url }); + + if (page) { + res.send(` + + `); + } + } catch (error) {} + } + async executeWebhook( req: WaitingWebhookRequest, res: express.Response, @@ -62,7 +82,7 @@ export class WaitingForms extends WaitingWebhooks { if (execution.status === 'running') { if (this.includeForms && req.method === 'GET') { - await this.reloadForm(executionId, res); + await this.reloadForm(req, res); return { noWebhookResponse: true }; } diff --git a/packages/cli/src/webhooks/waiting-webhooks.ts b/packages/cli/src/webhooks/waiting-webhooks.ts index 6f16163487..9529d04c04 100644 --- a/packages/cli/src/webhooks/waiting-webhooks.ts +++ b/packages/cli/src/webhooks/waiting-webhooks.ts @@ -1,4 +1,3 @@ -import axios from 'axios'; import type express from 'express'; import { FORM_NODE_TYPE, @@ -6,7 +5,6 @@ import { type IWorkflowBase, NodeHelpers, SEND_AND_WAIT_OPERATION, - sleep, WAIT_NODE_TYPE, Workflow, } from 'n8n-workflow'; @@ -19,7 +17,6 @@ import type { IExecutionResponse, IWorkflowDb } from '@/interfaces'; import { Logger } from '@/logging/logger.service'; import { NodeTypes } from '@/node-types'; import * as WebhookHelpers from '@/webhooks/webhook-helpers'; -import { getBase } from '@/workflow-execute-additional-data'; import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data'; import type { @@ -83,26 +80,6 @@ export class WaitingWebhooks implements IWebhookManager { }); } - protected async reloadForm(executionId: string, res: express.Response) { - try { - await sleep(1000); - - const { formWaitingBaseUrl } = await getBase(); - const url = `${formWaitingBaseUrl}/${executionId}`; - const page = await axios({ url }); - - if (page) { - res.send(` - - `); - } - } catch (error) {} - } - async executeWebhook( req: WaitingWebhookRequest, res: express.Response, @@ -221,7 +198,6 @@ export class WaitingWebhooks implements IWebhookManager { ); if (hasChildForms) { - await this.reloadForm(executionId, res); return { noWebhookResponse: true }; } } diff --git a/packages/cli/templates/form-trigger.handlebars b/packages/cli/templates/form-trigger.handlebars index 55b3fa46c7..08f6d2e290 100644 --- a/packages/cli/templates/form-trigger.handlebars +++ b/packages/cli/templates/form-trigger.handlebars @@ -751,6 +751,18 @@ .catch(function (error) { console.error('Error:', error); }); + + const isWaitingForm = window.location.href.includes('form-waiting'); + if(isWaitingForm) { + const interval = setInterval(function() { + const isSubmited = document.querySelector('#submitted-form').style.display; + if(isSubmited === 'block') { + clearInterval(interval); + return; + } + window.location.reload(); + }, 2000); + } } });