feat(clickTtHttpPageRoutes): implement form action rewriting and proxy for POST requests
- Added a new function to rewrite form actions in HTML to route submissions through the proxy, enhancing logging for login actions. - Implemented a POST endpoint for the proxy to handle form submissions, including validation for target URLs and forwarding requests with appropriate headers. - Enhanced error handling and response management for the new proxy functionality, ensuring robust interaction with external services.
This commit is contained in:
@@ -99,27 +99,32 @@ async function fetchWithLogging(options) {
|
||||
clubIdParam = null,
|
||||
userId = null,
|
||||
method = 'GET',
|
||||
body = null,
|
||||
headers: customHeaders = {},
|
||||
} = options;
|
||||
|
||||
const baseDomain = extractBaseDomain(url);
|
||||
const startTime = Date.now();
|
||||
|
||||
const headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||
'Accept-Language': 'de,en-US;q=0.7,en;q=0.3',
|
||||
...customHeaders,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method,
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||
'Accept-Language': 'de,en-US;q=0.7,en;q=0.3',
|
||||
},
|
||||
timeout: 30000,
|
||||
});
|
||||
const fetchOpts = { method, headers, timeout: 30000 };
|
||||
if (body && (method === 'POST' || method === 'PUT')) {
|
||||
fetchOpts.body = body;
|
||||
}
|
||||
const response = await fetch(url, fetchOpts);
|
||||
|
||||
const executionTimeMs = Date.now() - startTime;
|
||||
const contentType = response.headers.get('content-type') || null;
|
||||
const body = await response.text();
|
||||
const responseBody = await response.text();
|
||||
const success = response.ok;
|
||||
const snippet = createResponseSnippet(body);
|
||||
const snippet = createResponseSnippet(responseBody);
|
||||
|
||||
await HttpPageFetchLog.create({
|
||||
userId,
|
||||
@@ -143,8 +148,9 @@ async function fetchWithLogging(options) {
|
||||
success,
|
||||
status: response.status,
|
||||
contentType,
|
||||
body,
|
||||
body: responseBody,
|
||||
executionTimeMs,
|
||||
headers: response.headers,
|
||||
};
|
||||
} catch (error) {
|
||||
const executionTimeMs = Date.now() - startTime;
|
||||
|
||||
Reference in New Issue
Block a user