외부호출 기능(rest API)

This commit is contained in:
kjs
2025-09-26 17:11:18 +09:00
parent 9454e3a81f
commit 11b71b788a
19 changed files with 3177 additions and 243 deletions

View File

@@ -180,10 +180,57 @@ export class ExternalCallService {
body = this.processTemplate(body, templateData);
}
// 기본 헤더 준비
const headers = { ...(settings.headers || {}) };
// 인증 정보 처리
if (settings.authentication) {
switch (settings.authentication.type) {
case "api-key":
if (settings.authentication.apiKey) {
headers["X-API-Key"] = settings.authentication.apiKey;
}
break;
case "basic":
if (
settings.authentication.username &&
settings.authentication.password
) {
const credentials = Buffer.from(
`${settings.authentication.username}:${settings.authentication.password}`
).toString("base64");
headers["Authorization"] = `Basic ${credentials}`;
}
break;
case "bearer":
if (settings.authentication.token) {
headers["Authorization"] =
`Bearer ${settings.authentication.token}`;
}
break;
case "custom":
if (
settings.authentication.headerName &&
settings.authentication.headerValue
) {
headers[settings.authentication.headerName] =
settings.authentication.headerValue;
}
break;
// 'none' 타입은 아무것도 하지 않음
}
}
console.log(`🔐 [ExternalCallService] 인증 처리 완료:`, {
authType: settings.authentication?.type || "none",
hasAuthHeader: !!headers["Authorization"],
headers: Object.keys(headers),
});
return await this.makeHttpRequest({
url: settings.url,
method: settings.method,
headers: settings.headers || {},
headers: headers,
body: body,
timeout: settings.timeout || this.DEFAULT_TIMEOUT,
});
@@ -213,17 +260,36 @@ export class ExternalCallService {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), options.timeout);
const response = await fetch(options.url, {
// GET, HEAD 메서드는 body를 가질 수 없음
const method = options.method.toUpperCase();
const requestOptions: RequestInit = {
method: options.method,
headers: options.headers,
body: options.body,
signal: controller.signal,
});
};
// GET, HEAD 메서드가 아닌 경우에만 body 추가
if (method !== "GET" && method !== "HEAD" && options.body) {
requestOptions.body = options.body;
}
const response = await fetch(options.url, requestOptions);
clearTimeout(timeoutId);
const responseText = await response.text();
// 디버깅을 위한 로그 추가
console.log(`🔍 [ExternalCallService] HTTP 응답:`, {
url: options.url,
method: options.method,
status: response.status,
statusText: response.statusText,
ok: response.ok,
headers: Object.fromEntries(response.headers.entries()),
responseText: responseText.substring(0, 500), // 처음 500자만 로그
});
return {
success: response.ok,
statusCode: response.status,