1차 싱크 완료
This commit is contained in:
@@ -21,19 +21,24 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
const submitTarget = config?.submitTarget ?? "internal";
|
||||
const successMessage = config?.successMessage;
|
||||
const errorMessage = config?.errorMessage;
|
||||
|
||||
// 1) internal: 우리 서버에서 직접 처리하는 기본 모드
|
||||
if (submitTarget === "internal") {
|
||||
// TODO: 이곳에서 DB 저장이나 이메일 전송 등 실제 처리를 수행한다.
|
||||
console.log("[forms/submit][internal]", { name, email, message });
|
||||
return NextResponse.json({ ok: true });
|
||||
return NextResponse.json({ ok: true, message: successMessage });
|
||||
}
|
||||
|
||||
// 2) webhook: destinationUrl 로 서버에서 POST (Google Sheets 등 포함)
|
||||
if (submitTarget === "webhook") {
|
||||
const destinationUrl = config?.destinationUrl;
|
||||
if (!destinationUrl) {
|
||||
return NextResponse.json({ ok: false, error: "destinationUrl_missing" }, { status: 400 });
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "destinationUrl_missing", message: errorMessage },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const payloadFormat = config?.payloadFormat ?? "form";
|
||||
@@ -87,19 +92,25 @@ export async function POST(req: Request) {
|
||||
|
||||
if (!res.ok) {
|
||||
console.error("[forms/submit][webhook] remote error", res.status, await res.text().catch(() => ""));
|
||||
return NextResponse.json({ ok: false, error: "webhook_failed" }, { status: 502 });
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "webhook_failed", message: errorMessage },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("[forms/submit][webhook] fetch error", error);
|
||||
return NextResponse.json({ ok: false, error: "webhook_exception" }, { status: 500 });
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "webhook_exception", message: errorMessage },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
||||
console.log("[forms/submit][webhook] forwarded", { name, email, message, destinationUrl });
|
||||
return NextResponse.json({ ok: true });
|
||||
return NextResponse.json({ ok: true, message: successMessage });
|
||||
}
|
||||
|
||||
// 그 외 알 수 없는 모드는 internal 과 동일하게 처리
|
||||
console.warn("[forms/submit] unknown submitTarget, fallback to internal", submitTarget);
|
||||
console.log("[forms/submit][internal]", { name, email, message });
|
||||
return NextResponse.json({ ok: true });
|
||||
return NextResponse.json({ ok: true, message: successMessage });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user