feat: add http node timeout (#2465)

* fix $ in replacement string misinterpreted as regex special character

* add http timeout

* delete console log
This commit is contained in:
heheer
2024-08-21 20:23:35 +08:00
committed by GitHub
parent 113c57bcbe
commit 5627a4bfde
7 changed files with 90 additions and 10 deletions

View File

@@ -57,6 +57,7 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
system_httpHeader: httpHeader,
system_httpParams: httpParams = [],
system_httpJsonBody: httpJsonBody,
system_httpTimeout: httpTimeout,
[NodeInputKeyEnum.addInputParam]: dynamicInput,
...body
}
@@ -143,7 +144,8 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
url: httpReqUrl,
headers,
body: requestBody,
params
params,
timeout: httpTimeout
});
})();
@@ -199,13 +201,15 @@ async function fetchData({
url,
headers,
body,
params
params,
timeout
}: {
method: string;
url: string;
headers: Record<string, any>;
body: Record<string, any> | string;
params: Record<string, any>;
timeout: number;
}) {
const { data: response } = await axios({
method,
@@ -215,7 +219,7 @@ async function fetchData({
'Content-Type': 'application/json',
...headers
},
timeout: 120000,
timeout: timeout * 1000,
params: params,
data: ['POST', 'PUT', 'PATCH'].includes(method) ? body : undefined
});
@@ -308,7 +312,7 @@ function replaceVariable(text: string, obj: Record<string, any>) {
replacement.startsWith('"') && replacement.endsWith('"')
? replacement.slice(1, -1)
: replacement;
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), unquotedReplacement);
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), () => unquotedReplacement);
}
}
return text || '';