From 3067646ba21bd1d1ea4c9758d88049cf4eca61d4 Mon Sep 17 00:00:00 2001 From: jsyang Date: Fri, 29 Aug 2025 16:35:13 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9A=B4=EC=98=81=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=8B=A0=EA=B7=9C=EC=B6=94=EA=B0=80=EB=90=9C=EA=B1=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=EA=B1=B0=20=EC=9B=90=EB=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wr/.env.production | 17 ++++++- apps/wr/middleware.ts | 98 ++++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 51 deletions(-) diff --git a/apps/wr/.env.production b/apps/wr/.env.production index b68a23111..aef204e50 100644 --- a/apps/wr/.env.production +++ b/apps/wr/.env.production @@ -1,6 +1,6 @@ NEXT_PUBLIC_SITE_ID = WR NEXT_PUBLIC_PORT = 3000 -NEXT_PUBLIC_PROXY_HOST = https://wr.hasuon.or.kr +NEXT_PUBLIC_PROXY_HOST = http://wr.hasuon.or.kr NEXT_PUBLIC_SERVER_API_URL = http://apigateway.iipbs-dev.svc.cluster.local:8000 NEXT_PUBLIC_FO_SERVER_API_URL = https://wr.hasuon.or.kr/operation-service/api/v1 NEXT_PUBLIC_CS_SERVER_API_URL = http://apigateway.iipbs-dev.svc.cluster.local:8000 @@ -12,5 +12,18 @@ NEXT_PUBLIC_AUTH_USER_ID = token-id NEXT_PUBLIC_ACCESS_TOKEN = access-token NEXT_PUBLIC_REFRESH_TOKEN = refresh-token NEXT_PUBLIC_WR_SERVER_API_URL = https://wr.hasuon.or.kr/reuse-service/api/v1 +NEXT_PUBLIC_SEWERAGE_API_URL = https://wr.hasuon.or.kr/sewerage-service/api +NEXT_PUBLIC_NGII_URL = http://10.98.25.94:18080/openapi/Gettile.do?apiKey=BDE2BEF39DAFEC293AB6730150F222AC +#NEXT_PUBLIC_SERVER_API_URL = http://apigateway.iipbs-dev.svc.cluster.local:8000/api/v1 +#NEXT_PUBLIC_FO_SERVER_API_URL = http://apigateway.iipbs-dev.svc.cluster.local:8000/operation-service/api/v1 +#NEXT_PUBLIC_GEOSERVER_URL = https://hasudo.geo.rsonesoft.com/geoserver +#NEXT_PUBLIC_SEWERAGE_API_URL = http://apigateway.iipbs-dev.svc.cluster.local:8000/sewerage-service/api + + +NEXT_PUBLIC_FINDADRESS_URL=https://business.juso.go.kr/addrlink/addrLinkApi.do +NEXT_PUBLIC_WR_ADDRESS_KEY = U01TXOFVVEgyMDI1MDgyODE0MTAxNzExNjEyMjA= + + + + -NEXT_PUBLIC_SEWERAGE_API_URL = https://wr.hasuon.or.kr/sewerage-service/api \ No newline at end of file diff --git a/apps/wr/middleware.ts b/apps/wr/middleware.ts index aeadb869d..716a851b8 100644 --- a/apps/wr/middleware.ts +++ b/apps/wr/middleware.ts @@ -8,21 +8,16 @@ const serverApiUrl = CS_URL; const GEOSERVER_URL = process.env.NEXT_PUBLIC_GEOSERVER_URL || ""; const LX_GEOSERVER_URL = process.env.NEXT_PUBLIC_LX_GEOSERVER_URL || ""; const SEWERAGE_API_URL = process.env.NEXT_PUBLIC_SEWERAGE_API_URL || ""; +const REUSE_API_URL = process.env.NEXT_PUBLIC_WR_SERVER_API_URL || ""; +const OPERATION_API_URL = process.env.NEXT_PUBLIC_FO_SERVER_API_URL || ""; +const BUSINESS_JUSO_API_URL = process.env.NEXT_PUBLIC_FINDADRESS_URL || ""; +const AdressKey = process.env.NEXT_PUBLIC_WR_ADDRESS_KEY || ""; export function middleware(req: NextRequest) { const pathname = req.nextUrl.pathname; console.log(`[Middleware] Request URL: ${req.url}`); const searchParams = req.nextUrl.searchParams; - // if (pathname.startsWith("/server")) { - // const queryParams = searchParams.toString(); - // const newUrl = `${serverApiUrl}${pathname.replace("/server", "")}${ - // queryParams ? `?${queryParams}` : "" - // }`; - // console.log(`[Middleware] Rewriting from '/server' path to: ${newUrl}`); - // return NextResponse.rewrite(new URL(newUrl)); - // } - if (pathname.startsWith("/server")) { const decodedParams = Array.from(searchParams.entries()) .map(([key, value]) => `${key}=${decodeURIComponent(value)}`) @@ -35,7 +30,6 @@ export function middleware(req: NextRequest) { } if (pathname === "/") { - console.log(" maim 화면이동 "); return NextResponse.redirect(new URL("/map/mainMap", req.url)); } @@ -44,7 +38,6 @@ export function middleware(req: NextRequest) { const Authorization = req.cookies.get(CLAIM_NAME)?.value; const newUrl = `${serverApiUrl}${pathname}`; - console.log("Authorization cms-service ", Authorization); if (Authorization) requestHeaders.set(CLAIM_NAME, Authorization); //if (userId) requestHeaders.set(AUTH_USER_ID, userId); @@ -72,40 +65,6 @@ export function middleware(req: NextRequest) { headers: requestHeaders, }); } - - if (pathname.startsWith("/operation-service")) { - const requestHeaders = new Headers(req.headers); - const token = req.cookies.get(CLAIM_NAME)?.value; - const userId = req.cookies.get(AUTH_USER_ID)?.value; - const newUrl = `${serverApiUrl}${pathname}`; - - if (token) requestHeaders.set(CLAIM_NAME, token); - if (userId) requestHeaders.set(AUTH_USER_ID, userId); - - console.log( - `[Middleware] Rewriting from '/operation-service' path to: ${newUrl}` - ); - return NextResponse.rewrite(new URL(newUrl), { - headers: requestHeaders, - }); - } - - if (pathname.startsWith("/reuse-service")) { - const requestHeaders = new Headers(req.headers); - const token = req.cookies.get(CLAIM_NAME)?.value; - const userId = req.cookies.get(AUTH_USER_ID)?.value; - const newUrl = `${serverApiUrl}${pathname}`; - - if (token) requestHeaders.set(CLAIM_NAME, token); - if (userId) requestHeaders.set(AUTH_USER_ID, userId); - - console.log( - `[Middleware] Rewriting from '/reuse-service' path to: ${newUrl}` - ); - return NextResponse.rewrite(new URL(newUrl), { - headers: requestHeaders, - }); - } if (pathname.startsWith("/user-service")) { const requestHeaders = new Headers(req.headers); @@ -122,7 +81,8 @@ export function middleware(req: NextRequest) { if (pathname.startsWith("/geoserver")) { let queryParams = searchParams.toString(); const typename = searchParams.get("TYPENAME"); - console.log("typename ", typename); + const startYmd = searchParams.get("START_YMD") ?? null; + const endYmd = searchParams.get("END_YMD") ?? null; let newUrl = `${GEOSERVER_URL}${pathname.replace("/geoserver", "")}${queryParams ? `?${queryParams}` : ""}`; @@ -148,15 +108,18 @@ export function middleware(req: NextRequest) { typename == "hasudo:tb_wr_rswtr_fclt" || //중수도시설 typename == "hasudo:tb_wr_htdfl_fclt" || //온배수시설 typename == "hasudo:tb_wr_ruse_fclt_dmd_co" || //수요처 - typename == "hasudo:tb_wr_tmpr_dmd_co" //잠재수요처 + typename == "hasudo:tb_wr_tmpr_dmd_co" || //잠재수요처 + typename?.startsWith("hasudo:drought") //가뭄 지도 ) { const url = req.nextUrl.clone(); url.searchParams.set("TYPENAME", typename.replace("hasudo:", "")); + if (startYmd) url.searchParams.set("startYmd", startYmd); + if (endYmd) url.searchParams.set("endYmd", endYmd); queryParams = url.searchParams.toString(); newUrl = `${SEWERAGE_API_URL}/v1/map/geometry${queryParams ? `?${queryParams}` : ""}`; } - console.log(`[Middleware] Rewriting from '/geoserver' path to: ${newUrl}`); + //console.log(`[Middleware] Rewriting from '/geoserver' path to: ${newUrl}`); return NextResponse.rewrite(new URL(newUrl)); } @@ -165,10 +128,46 @@ export function middleware(req: NextRequest) { const newUrl = `${SEWERAGE_API_URL}${pathname.replace("/sewerage-service/api", "")}${ queryParams ? `?${queryParams}` : "" }`; - console.log(`[Middleware] Rewriting from '/sewerage' path to: ${newUrl}`); + console.log(`[Middleware] Rewriting from '/geoserver' path to: ${newUrl}`); return NextResponse.rewrite(new URL(newUrl)); } + if (pathname.startsWith("/reuse-service")) { + const queryParams = searchParams.toString(); + const newUrl = `${REUSE_API_URL}${pathname.replace("/reuse-service", "")}${ + queryParams ? `?${queryParams}` : "" + }`; + console.log(`[Middleware] Rewriting from '/reuse-service' path to: ${newUrl}`); + return NextResponse.rewrite(new URL(newUrl)); + } + + if (pathname.startsWith("/operation-service")) { + const queryParams = searchParams.toString(); + const newUrl = `${OPERATION_API_URL}${pathname.replace("/operation-service", "")}${ + queryParams ? `?${queryParams}` : "" + }`; + console.log(`[Middleware] Rewriting from '/operation-service' path to: ${newUrl}`); + return NextResponse.rewrite(new URL(newUrl)); + } + + + if (pathname.startsWith("/bussiness-juso-service")) { + console.log('AdressKey ', AdressKey) + const params = new URLSearchParams({ + currentPage: "1", // 원하는 페이지 + countPerPage: "5", // 페이지당 결과 수 + keyword: searchParams.get("keyword") || "", // 검색어(주소) + confmKey: AdressKey, // 인증키 인터넷용 패쇄망용은 따로 발급 필요 즉 middleware에서 치환해서 사용해야할듯 + resultType: "json", // 결과 형식 기본은 xml + }); + const newUrl = `${BUSINESS_JUSO_API_URL}?${params.toString()}`; + console.log(`[Middleware] Request to business.juso.go.kr`); + console.log(req.url); + console.log(`[Middleware] Rewriting from '/business.juso.go.kr' path to: ${newUrl}`); + return NextResponse.rewrite(new URL(newUrl)); + } + + return NextResponse.next(); } @@ -182,6 +181,7 @@ export const config = { "/sewerage-service/:path*", "/reuse-service/:path*", "/operation-service/:path*", + "/bussiness-juso-service/:path*", "/" ], };