diff options
Diffstat (limited to 'app/api')
| -rw-r--r-- | app/api/juso/route.ts | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/app/api/juso/route.ts b/app/api/juso/route.ts new file mode 100644 index 00000000..258e51d3 --- /dev/null +++ b/app/api/juso/route.ts @@ -0,0 +1,69 @@ +"use server"; + +import { NextRequest, NextResponse } from "next/server"; + +const JUSO_URL = "https://business.juso.go.kr/addrlink/addrLinkUrl.do"; + +export async function GET() { + const confmKey = process.env.JUSO_API_KEY || ""; + const returnUrl = `${process.env.NEXT_PUBLIC_BASE_URL || ""}/api/juso`; + const resultType = "4"; + + const html = ` + <!doctype html> + <html lang="ko"> + <head><meta charset="utf-8" /></head> + <body onload="document.getElementById('jusoForm').submit();"> + <form id="jusoForm" name="jusoForm" method="post" action="${JUSO_URL}"> + <input type="hidden" name="confmKey" value="${confmKey}" /> + <input type="hidden" name="returnUrl" value="${returnUrl}" /> + <input type="hidden" name="resultType" value="${resultType}" /> + </form> + </body> + </html> + `; + + return new NextResponse(html, { + status: 200, + headers: { "Content-Type": "text/html; charset=utf-8" }, + }); +} + +export async function POST(req: NextRequest) { + const formData = await req.formData(); + + const zipNo = String(formData.get("zipNo") || ""); + const roadAddrPart1 = String(formData.get("roadAddrPart1") || ""); + const roadAddrPart2 = String(formData.get("roadAddrPart2") || ""); + const addrDetail = String(formData.get("addrDetail") || ""); + + const origin = process.env.NEXT_PUBLIC_BASE_URL || "*"; + + const script = ` + <script> + (function() { + try { + const payload = { + zipNo: ${JSON.stringify(zipNo)}, + roadAddrPart1: ${JSON.stringify(roadAddrPart1)}, + roadAddrPart2: ${JSON.stringify(roadAddrPart2)}, + addrDetail: ${JSON.stringify(addrDetail)} + }; + if (window.opener && !window.opener.closed) { + window.opener.postMessage({ type: "JUSO_SELECTED", payload }, "${origin}"); + } + } catch (e) { + console.error(e); + } finally { + window.close(); + } + })(); + </script> + `; + + return new NextResponse(script, { + status: 200, + headers: { "Content-Type": "text/html; charset=utf-8" }, + }); +} + |
