리스트 위젯 REST API 기능 개선

This commit is contained in:
dohyeons
2025-12-11 10:48:48 +09:00
parent e84764dc2b
commit bccb8a6330
5 changed files with 211 additions and 25 deletions

View File

@@ -285,16 +285,46 @@ export function ListWidget({ element, onConfigUpdate }: ListWidgetProps) {
});
}
// 요청 메서드 (기본값: GET)
const requestMethod = element.dataSource.method || "GET";
// 요청 body (POST, PUT, PATCH인 경우)
let requestBody = undefined;
if (["POST", "PUT", "PATCH"].includes(requestMethod) && element.dataSource.body) {
try {
requestBody = typeof element.dataSource.body === "string"
? JSON.parse(element.dataSource.body)
: element.dataSource.body;
} catch {
requestBody = element.dataSource.body;
}
}
// headers를 KeyValuePair[] 에서 객체로 변환
const headersObj: Record<string, string> = {};
if (element.dataSource.headers && Array.isArray(element.dataSource.headers)) {
element.dataSource.headers.forEach((h: any) => {
if (h.key && h.value) {
headersObj[h.key] = h.value;
}
});
} else if (element.dataSource.headers && typeof element.dataSource.headers === "object") {
Object.assign(headersObj, element.dataSource.headers);
}
const response = await fetch(getApiUrl("/api/dashboards/fetch-external-api"), {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({
url: element.dataSource.endpoint,
method: "GET",
headers: element.dataSource.headers || {},
method: requestMethod,
headers: headersObj,
queryParams: Object.fromEntries(params),
body: requestBody,
externalConnectionId: element.dataSource.externalConnectionId,
}),
});