fix(generator): use endpoint.url directly in buildRequest to fix URL construction bug
The previous implementation used `new URL(endpoint.url, window.location.origin)` which incorrectly constructed URLs based on the current page's origin. This broke when endpoint URLs were already complete URLs (e.g., http://20.76.57.61:18080/...). The fix uses endpoint.url directly since LLM extraction already provides complete URLs. Also changed from GET with query params to POST with JSON body to match typical API expectations. 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
@@ -306,18 +306,12 @@ function validateArgs(args) {{
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
function buildRequest(args, endpoint) {{
|
function buildRequest(args, endpoint) {{
|
||||||
const url = new URL(endpoint.url, window.location.origin);
|
// Use endpoint.url directly - it's already a complete URL
|
||||||
const params = {{ ...STATIC_PARAMS, ...args }};
|
const url = endpoint.url;
|
||||||
for (const [key, value] of Object.entries(params)) {{
|
const method = endpoint.method || 'POST';
|
||||||
if (value !== undefined && value !== null) {{
|
const headers = {{ 'Content-Type': 'application/json' }};
|
||||||
url.searchParams.set(key, String(value));
|
const body = JSON.stringify({{ ...STATIC_PARAMS, ...args }});
|
||||||
}}
|
return {{ url, method, headers, body }};
|
||||||
}}
|
|
||||||
return {{
|
|
||||||
url: url.toString(),
|
|
||||||
method: endpoint.method || 'GET',
|
|
||||||
headers: {{ 'Content-Type': 'application/json' }}
|
|
||||||
}};
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
function normalizeRows(rawData) {{
|
function normalizeRows(rawData) {{
|
||||||
@@ -360,7 +354,8 @@ const defaultDeps = {{
|
|||||||
const request = buildRequest(args, endpoint);
|
const request = buildRequest(args, endpoint);
|
||||||
const response = await fetch(request.url, {{
|
const response = await fetch(request.url, {{
|
||||||
method: request.method,
|
method: request.method,
|
||||||
headers: request.headers
|
headers: request.headers,
|
||||||
|
body: request.body
|
||||||
}});
|
}});
|
||||||
if (!response.ok) throw new Error(`HTTP ${{response.status}}: ${{response.statusText}}`);
|
if (!response.ok) throw new Error(`HTTP ${{response.status}}: ${{response.statusText}}`);
|
||||||
return response.json();
|
return response.json();
|
||||||
|
|||||||
Reference in New Issue
Block a user