From 34251fa336e5de7424fbdf205ceeebe0bbc3fcf3 Mon Sep 17 00:00:00 2001 From: Daniel D'Abate Date: Fri, 7 Jun 2024 13:04:25 +0200 Subject: [PATCH] Bugfix - Add x-forwarded-proto as source for http protocol for base url and add base url field to ChatflowTool (#2592) --- .../nodes/tools/ChatflowTool/ChatflowTool.ts | 14 ++++++++++++-- packages/server/src/utils/buildChatflow.ts | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts b/packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts index e9a0811eb..df5e50fe1 100644 --- a/packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts +++ b/packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts @@ -22,7 +22,7 @@ class ChatflowTool_Tools implements INode { constructor() { this.label = 'Chatflow Tool' this.name = 'ChatflowTool' - this.version = 1.0 + this.version = 2.0 this.type = 'ChatflowTool' this.icon = 'chatflowTool.svg' this.category = 'Tools' @@ -56,6 +56,16 @@ class ChatflowTool_Tools implements INode { placeholder: 'State of the Union QA - useful for when you need to ask questions about the most recent state of the union address.' }, + { + label: 'Base URL', + name: 'baseURL', + type: 'string', + description: + 'Base URL to Flowise. By default, it is the URL of the incoming request. Useful when you need to execute the Chatflow through an alternative route.', + placeholder: 'http://localhost:3000', + optional: true, + additionalParams: true + }, { label: 'Use Question from Chat', name: 'useQuestionFromChat', @@ -107,7 +117,7 @@ class ChatflowTool_Tools implements INode { const useQuestionFromChat = nodeData.inputs?.useQuestionFromChat as boolean const customInput = nodeData.inputs?.customInput as string - const baseURL = options.baseURL as string + const baseURL = (nodeData.inputs?.baseURL as string) || (options.baseURL as string) const credentialData = await getCredentialData(nodeData.credential ?? '', options) const chatflowApiKey = getCredentialParam('chatflowApiKey', credentialData, nodeData) diff --git a/packages/server/src/utils/buildChatflow.ts b/packages/server/src/utils/buildChatflow.ts index 749faea7d..85d4472bc 100644 --- a/packages/server/src/utils/buildChatflow.ts +++ b/packages/server/src/utils/buildChatflow.ts @@ -54,7 +54,9 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter try { const appServer = getRunningExpressApp() const chatflowid = req.params.id - const baseURL = `${req.protocol}://${req.get('host')}` + + const httpProtocol = req.get('x-forwarded-proto') || req.protocol + const baseURL = `${httpProtocol}://${req.get('host')}` let incomingInput: IncomingInput = req.body let nodeToExecuteData: INodeData