리스트 위젯 REST API 기능 개선
This commit is contained in:
@@ -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,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user