From 7cb4f624ee1b9bc26677b015a4b46278518c0315 Mon Sep 17 00:00:00 2001 From: ljpark Date: Thu, 2 Oct 2025 13:51:48 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8C=80=EB=AF=BC=20=EB=AF=B8=EB=93=A4?= =?UTF-8?q?=EC=9B=A8=EC=96=B4=20=EA=B2=BD=EC=9C=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/dm/.env.local | 2 +- apps/dm/app/(popup-layout)/map/service/map.ts | 9 +++-- apps/dm/app/store/map/index.tsx | 10 +++++- apps/dm/components/ui/api/index.ts | 23 +++++++++--- apps/dm/components/ui/config/index.ts | 7 ++-- apps/dm/middleware.ts | 27 ++++++++++++-- apps/fo/.env.local | 2 +- apps/fo/middleware.ts | 35 ++++++++++++------- 8 files changed, 85 insertions(+), 30 deletions(-) diff --git a/apps/dm/.env.local b/apps/dm/.env.local index 3c390c8bd..c43f5af55 100644 --- a/apps/dm/.env.local +++ b/apps/dm/.env.local @@ -5,7 +5,7 @@ NEXT_PUBLIC_ACCESS_TOKEN = access-token NEXT_PUBLIC_REFRESH_TOKEN = refresh-token NEXT_PUBLIC_PORT = 3005 #NEXT_PUBLIC_PROXY_HOST = http://con.mind-one.co.kr:11035 -NEXT_PUBLIC_PROXY_HOST = http://localhost:3005/ +NEXT_PUBLIC_PROXY_HOST = http://localhost:3005 NEXT_PUBLIC_DM_SERVER_API_URL = http://con.mind-one.co.kr:11080/api/v1 NEXT_PUBLIC_SERVER_API_URL = http://dev.onasys.co.kr:8000 NEXT_PUBLIC_FO_SERVER_API_URL = http://con.mind-one.co.kr:11082/api/v1 diff --git a/apps/dm/app/(popup-layout)/map/service/map.ts b/apps/dm/app/(popup-layout)/map/service/map.ts index aa98a0bc2..b527ac1c4 100644 --- a/apps/dm/app/(popup-layout)/map/service/map.ts +++ b/apps/dm/app/(popup-layout)/map/service/map.ts @@ -1,9 +1,8 @@ - /** * 관망도 API */ - const API_URL = `${process.env.NEXT_PUBLIC_SEWERAGE_API_URL}/v1/map` - const REUSE_API_URL = `${process.env.NEXT_PUBLIC_REUSE_API_URL}` +import { DEV_URL_WR, DEV_URL_SN } from "@/components/ui/config"; +const PROXY_HOST = process.env.NEXT_PUBLIC_PROXY_HOST || ""; export type LyrStngProps = { lyr_sn: string @@ -31,7 +30,7 @@ export type LyrStngProps = { export const mapService = { //레이어 설정 조회 getLyrStngs: async () => { - const response = await fetch(`${API_URL}/lyrStngs/DM_NETWORK`, { + const response = await fetch(`${PROXY_HOST}${DEV_URL_SN}/app/v1/map/lyrStngs/DM_NETWORK`, { method: 'GET', headers: { 'Accept': 'application/json', @@ -45,7 +44,7 @@ export const mapService = { return response.json(); }, getPbnstRuseFclts: async (ruseFcltPk:any) => { - const response = await fetch(`${REUSE_API_URL}/reuseFc/pubFc/${ruseFcltPk}`, { + const response = await fetch(`${PROXY_HOST}${DEV_URL_WR}/api/v1/reuseFc/pubFc/${ruseFcltPk}`, { method: 'GET', headers: { 'Accept': 'application/json', diff --git a/apps/dm/app/store/map/index.tsx b/apps/dm/app/store/map/index.tsx index 5ed066f73..79bdd19e5 100644 --- a/apps/dm/app/store/map/index.tsx +++ b/apps/dm/app/store/map/index.tsx @@ -1,7 +1,13 @@ +import { AUTH_USER_ID, CLAIM_NAME } from "@/src/shared/config"; import { fetchType, getFetch } from "@/components/ui/api"; import { DEV_URL_FO } from "@/components/ui/config"; +import { getCookie } from "@common/components/lib/cookie"; import type { FacilityInfo, SubsInfo } from "./type"; +const PROXY_HOST = process.env.NEXT_PUBLIC_PROXY_HOST; +const tokenId = getCookie(AUTH_USER_ID); +const Authorization = getCookie(CLAIM_NAME); + const checkWrRegList = async () => { const wrRegList = await getFetch(fetchType.WR, `/reuseFc/pubFc`); return wrRegList; @@ -22,10 +28,12 @@ const getRuseFclt = async ( url = url + `/${searchTxt}`; } - const response = await fetch(DEV_URL_FO + url, { + const response = await fetch(PROXY_HOST + DEV_URL_FO + url, { method: "POST", headers: { "Content-Type": "application/json", + [AUTH_USER_ID]: tokenId ?? "", + [CLAIM_NAME]: Authorization ?? "", }, body: JSON.stringify(ruseList), }); diff --git a/apps/dm/components/ui/api/index.ts b/apps/dm/components/ui/api/index.ts index 28644b00e..c8f2cc9e7 100644 --- a/apps/dm/components/ui/api/index.ts +++ b/apps/dm/components/ui/api/index.ts @@ -1,5 +1,11 @@ //8880 +import { AUTH_USER_ID, CLAIM_NAME } from "@/src/shared/config"; import { DEV_URL_FO, DEV_URL_WR } from "../config"; +import { getCookie } from "@common/components/lib/cookie"; + +const PROXY_HOST = process.env.NEXT_PUBLIC_PROXY_HOST; +const tokenId = getCookie(AUTH_USER_ID); +const Authorization = getCookie(CLAIM_NAME); export const fetchType = { COMMON: "common", @@ -13,10 +19,13 @@ interface RequestParams { export const getFetch = async (type: string, url: string) => { const baseUrl = type === fetchType.FO ? DEV_URL_FO : DEV_URL_WR; - const response = await fetch(baseUrl + url, { + console.log("호출주소 ", PROXY_HOST+baseUrl + url); + const response = await fetch(PROXY_HOST+baseUrl + url, { method: "GET", headers: { accept: "application/json", + [AUTH_USER_ID]: tokenId ?? "", + [CLAIM_NAME]: Authorization ?? "", }, }); @@ -28,10 +37,12 @@ export const getFetch = async (type: string, url: string) => { }; export const postFetch = async (url: string, params: RequestParams) => { - const response = await fetch(DEV_URL_WR + url, { + const response = await fetch(PROXY_HOST+DEV_URL_WR + url, { method: "POST", headers: { "Content-Type": "application/json", + [AUTH_USER_ID]: tokenId ?? "", + [CLAIM_NAME]: Authorization ?? "", }, body: JSON.stringify(params), }); @@ -43,10 +54,12 @@ export const postFetch = async (url: string, params: RequestParams) => { }; export const putFetch = async (url: string, params: RequestParams) => { - const response = await fetch(DEV_URL_WR + url, { + const response = await fetch(PROXY_HOST+DEV_URL_WR + url, { method: "PUT", headers: { "Content-Type": "application/json", + [AUTH_USER_ID]: tokenId ?? "", + [CLAIM_NAME]: Authorization ?? "", }, body: JSON.stringify(params), }); @@ -58,10 +71,12 @@ export const putFetch = async (url: string, params: RequestParams) => { }; export const deleteFetch = async (url: string, params: RequestParams) => { - const response = await fetch(DEV_URL_WR + url, { + const response = await fetch(PROXY_HOST+DEV_URL_WR + url, { method: "DELETE", headers: { "Content-Type": "application/json", + [AUTH_USER_ID]: tokenId ?? "", + [CLAIM_NAME]: Authorization ?? "", }, body: JSON.stringify(params), }); diff --git a/apps/dm/components/ui/config/index.ts b/apps/dm/components/ui/config/index.ts index 2ed4ef03d..1585bb767 100644 --- a/apps/dm/components/ui/config/index.ts +++ b/apps/dm/components/ui/config/index.ts @@ -1,5 +1,6 @@ -import { PROXY_HOST, SERVER_API_FO_URL, SERVER_API_WR_URL } from "@/src/shared/config/env"; +import { PROXY_HOST } from "@/src/shared/config/env"; export const LOCAL_URL = PROXY_HOST; -export const DEV_URL_FO = SERVER_API_FO_URL; -export const DEV_URL_WR = SERVER_API_WR_URL; +export const DEV_URL_FO = "/operation-service"; +export const DEV_URL_WR = "/reuse-service"; +export const DEV_URL_SN = "/sewerage-service"; diff --git a/apps/dm/middleware.ts b/apps/dm/middleware.ts index 4ac2e3d99..8616a6e80 100644 --- a/apps/dm/middleware.ts +++ b/apps/dm/middleware.ts @@ -1,5 +1,6 @@ import { NextRequest, NextResponse } from "next/server"; import { CLAIM_NAME, AUTH_USER_ID } from "./src/shared/config"; +import { SERVER_API_FO_URL, SERVER_API_WR_URL } from "./src/shared/config/env"; // const CLAIM_NAME = "Authorization"; // const AUTH_USER_ID = "token-id"; @@ -115,12 +116,30 @@ export function middleware(req: NextRequest) { return NextResponse.rewrite(new URL(newUrl)); } - if (pathname.startsWith("/sewerage-service")) { + if (pathname.startsWith("/reuse-service")) { const queryParams = searchParams.toString(); - const newUrl = `${SEWERAGE_API_URL}${pathname.replace("/sewerage-service/api", "")}${ + const newUrl = `${SERVER_API_WR_URL}${pathname.replace("/reuse-service", "")}${ queryParams ? `?${queryParams}` : "" }`; - console.log(`[Middleware] Rewriting from '/geoserver' path to: ${newUrl}`); + 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 = `${SERVER_API_FO_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("/sewerage-service")) { + const queryParams = searchParams.toString(); + const newUrl = `${SEWERAGE_API_URL}${pathname.replace("/sewerage-service", "")}${ + queryParams ? `?${queryParams}` : "" + }`; + console.log(`[Middleware] Rewriting from '/sewerage-service' path to: ${newUrl}`); return NextResponse.rewrite(new URL(newUrl)); } if (pathname.startsWith("/bussiness-juso-service")) { @@ -150,6 +169,8 @@ export const config = { "/user-service/:path*", "/attach-service/:path*", "/geoserver/:path*", + "/operation-service/:path*", + "/reuse-service/:path*", "/sewerage-service/:path*", "/bussiness-juso-service/:path*", "/", diff --git a/apps/fo/.env.local b/apps/fo/.env.local index 70b477f17..adaac0461 100644 --- a/apps/fo/.env.local +++ b/apps/fo/.env.local @@ -14,5 +14,5 @@ NEXT_PUBLIC_ACCESS_TOKEN = access-token NEXT_PUBLIC_REFRESH_TOKEN = refresh-token NEXT_PUBLIC_NGII_URL = https://map.ngii.go.kr/openapi/Gettile.do?apiKey=04trYP9_xwLAfALjwZ-B8g NEXT_PUBLIC_SEWERAGE_API_URL=http://con.mind-one.co.kr:11083/sewerage-service/api # 개발 서버 API -NEXT_PUBLIC_DC_URL = https://apigateway.apps.rsonesoft.com +NEXT_PUBLIC_DC_URL = https://apigateway.apps.rsonesoft.com/dc-service REACT_EDITOR=atom \ No newline at end of file diff --git a/apps/fo/middleware.ts b/apps/fo/middleware.ts index f0918c345..1d8fe949c 100644 --- a/apps/fo/middleware.ts +++ b/apps/fo/middleware.ts @@ -65,12 +65,12 @@ export function middleware(req: NextRequest) { return NextResponse.rewrite(new URL(newUrl)); } - if (pathname.startsWith("/sewerage-service/api/v1/map/geometry")) { + if (pathname.startsWith("/sewerage-service")) { const queryParams = searchParams.toString(); - const newUrl = `${SEWERAGE_API_URL}${pathname.replace("/sewerage-service/api", "")}${ + const newUrl = `${SEWERAGE_API_URL}${pathname.replace("/sewerage-service", "")}${ queryParams ? `?${queryParams}` : "" }`; - console.log(`[Middleware] Rewriting from '/geoserver' path to: ${newUrl}`); + console.log(`[Middleware] Rewriting from '/sewerage-service' path to: ${newUrl}`); return NextResponse.rewrite(new URL(newUrl)); } @@ -110,12 +110,21 @@ export function middleware(req: NextRequest) { } if (pathname.startsWith("/dc-service")) { + const requestHeaders = new Headers(req.headers); const queryParams = searchParams.toString(); const newUrl = `${DC_URL}${pathname.replace("/dc-service", "")}${ queryParams ? `?${queryParams}` : "" }`; console.log(`[Middleware] Rewriting from '/dc-service' path to: ${newUrl}`); - return NextResponse.rewrite(new URL(newUrl)); + + const token = req.cookies.get(CLAIM_NAME)?.value; + const userId = req.cookies.get(AUTH_USER_ID)?.value; + if (token) requestHeaders.set(CLAIM_NAME, token); + if (userId) requestHeaders.set(AUTH_USER_ID, userId); + + return NextResponse.rewrite(new URL(newUrl), { + headers: requestHeaders, + }); } if (pathname.startsWith("/user-service")) { @@ -138,13 +147,15 @@ export function middleware(req: NextRequest) { export const config = { matcher: [ - "/", - "/server/:path*", - "/geoserver/:path*", - "/attach-service/:path*", - "/user-service/:path*", - "/cms-service/:path*", - "/operation-service/:path*", - "/reuse-service/:path*", + "/", + "/server/:path*", + "/geoserver/:path*", + "/sewerage-service/:path*", + "/attach-service/:path*", + "/user-service/:path*", + "/cms-service/:path*", + "/operation-service/:path*", + "/reuse-service/:path*", + "/dc-service/:path*", ], };