
--- client/resources/api/index.js
+++ client/resources/api/index.js
... | ... | @@ -8,8 +8,18 @@ |
8 | 8 |
} |
9 | 9 |
}); |
10 | 10 |
|
11 |
+const excludeCtxUrls = [ |
|
12 |
+ '/admin/cntxtPth/findLatestCntxtPth.json' // Context Path 정보 호출 |
|
13 |
+] |
|
14 |
+ |
|
11 | 15 |
apiClient.interceptors.request.use( |
12 | 16 |
config => { |
17 |
+ const excludeCtxUrl = excludeCtxUrls.some(url => config.url.includes(url)); |
|
18 |
+ const contextPath = store.state.contextPath || ''; |
|
19 |
+ if(contextPath != '/' && !excludeCtxUrl) { |
|
20 |
+ config.url = contextPath + config.url; // 요청 시 Context Path 추가 |
|
21 |
+ } |
|
22 |
+ |
|
13 | 23 |
config.headers.Authorization = store.state.authorization; // 요청 시 AccessToken 추가 |
14 | 24 |
return config; |
15 | 25 |
}, |
--- client/resources/api/router.js
+++ client/resources/api/router.js
... | ... | @@ -1,5 +1,9 @@ |
1 | 1 |
import apiClient from "./index"; |
2 | 2 |
|
3 |
+export const getCntxtPth = () => { |
|
4 |
+ return apiClient.get(`/admin/cntxtPth/findLatestCntxtPth.json`); |
|
5 |
+} |
|
6 |
+ |
|
3 | 7 |
export const findAll = () => { |
4 | 8 |
return apiClient.post(`/sys/contsType/findByContsAuthrtSys.json`); |
5 | 9 |
} |
--- client/views/pages/AppRouter.js
+++ client/views/pages/AppRouter.js
... | ... | @@ -21,9 +21,26 @@ |
21 | 21 |
}, |
22 | 22 |
]; |
23 | 23 |
|
24 |
-import { findAll, accessCheck } from "../../resources/api/router"; |
|
24 |
+import { getCntxtPth, findAll, accessCheck } from "../../resources/api/router"; |
|
25 | 25 |
import { save } from "../../resources/api/cntnStats"; |
26 | 26 |
import { mdiConsoleLine } from "@mdi/js"; |
27 |
+ |
|
28 |
+// Context Path 정보 호출 |
|
29 |
+async function getContextPath() { |
|
30 |
+ try { |
|
31 |
+ const res = await getCntxtPth(); |
|
32 |
+ if (res.status == 200) { |
|
33 |
+ const ctx = res.data.data || ""; // Context Path 정보 |
|
34 |
+ store.commit("setContextPath", ctx); // Context Path 정보 저장 |
|
35 |
+ return ctx; |
|
36 |
+ }else { |
|
37 |
+ store.commit("setStoreReset"); |
|
38 |
+ window.location = '/' |
|
39 |
+ } |
|
40 |
+ } catch (error) { |
|
41 |
+ return []; |
|
42 |
+ } |
|
43 |
+} |
|
27 | 44 |
|
28 | 45 |
// 라우터 정보 호출 |
29 | 46 |
async function fetchRoutes() { |
... | ... | @@ -44,6 +61,20 @@ |
44 | 61 |
} catch (error) { |
45 | 62 |
return []; |
46 | 63 |
} |
64 |
+} |
|
65 |
+ |
|
66 |
+// Context Path를 라우터에 추가하는 함수 |
|
67 |
+function addContextPathToRoutes(routes, contextPath) { |
|
68 |
+ return routes.map(route => { |
|
69 |
+ const newRoute = { |
|
70 |
+ ...route, |
|
71 |
+ path: contextPath + route.path |
|
72 |
+ }; |
|
73 |
+ // if (route.children && route.children.length > 0) { |
|
74 |
+ // newRoute.children = addContextPathToRoutes(route.children, contextPath); |
|
75 |
+ // } |
|
76 |
+ return newRoute; |
|
77 |
+ }); |
|
47 | 78 |
} |
48 | 79 |
|
49 | 80 |
// 접근 제어 확인 |
... | ... | @@ -113,8 +144,11 @@ |
113 | 144 |
} |
114 | 145 |
|
115 | 146 |
export default async function createAppRouter() { |
147 |
+ const ctx = await getContextPath(); // DB에 적재된 Context Path 정보 호출 |
|
116 | 148 |
const dynamicRoutes = await fetchRoutes(); // DB에 적재된 라우터 정보 호출 |
117 |
- const newRoutes = beforeRoutes.concat(dynamicRoutes); // 기존 라우터 정보와 합치기 |
|
149 |
+ const prefixedBeforeRoutes = addContextPathToRoutes(beforeRoutes, ctx); // 기존 라우터 정보에 Context Path 추가 |
|
150 |
+ const prefixedDynamicRoutes = addContextPathToRoutes(dynamicRoutes, ctx); // DB에 적재된 라우터 정보에 Context Path 추가 |
|
151 |
+ const newRoutes = prefixedBeforeRoutes.concat(prefixedDynamicRoutes); // 기존 라우터 정보와 합치기 |
|
118 | 152 |
const AppRouter = createRouter({ |
119 | 153 |
history: createWebHistory(), |
120 | 154 |
routes: newRoutes, |
--- client/views/pages/AppStore.js
+++ client/views/pages/AppStore.js
... | ... | @@ -11,7 +11,8 @@ |
11 | 11 |
menu: null, |
12 | 12 |
path: null, |
13 | 13 |
roles: [{authority: "ROLE_NONE"}], |
14 |
- pageAuth: null |
|
14 |
+ pageAuth: null, |
|
15 |
+ contextPath: null, |
|
15 | 16 |
}, |
16 | 17 |
getters: { |
17 | 18 |
getAuthorization: function () {}, |
... | ... | @@ -52,6 +53,7 @@ |
52 | 53 |
state.roles = [{authority: "ROLE_NONE"}]; |
53 | 54 |
state.menu = null; |
54 | 55 |
state.pageAuth = null; |
56 |
+ state.contextPath = null; |
|
55 | 57 |
}, |
56 | 58 |
setPageAuth(state, newValue) { |
57 | 59 |
state.pageAuth = newValue; |
... | ... | @@ -59,6 +61,9 @@ |
59 | 61 |
setMenuList(state, menuList) { |
60 | 62 |
state.menuList = menuList; |
61 | 63 |
}, |
64 |
+ setContextPath(state, ctx) { |
|
65 |
+ state.contextPath = ctx; |
|
66 |
+ } |
|
62 | 67 |
}, |
63 | 68 |
actions: { |
64 | 69 |
async logout({ commit }) { |
... | ... | @@ -101,6 +106,6 @@ |
101 | 106 |
}, |
102 | 107 |
setStoreReset({commit}) { |
103 | 108 |
commit("setStoreReset"); |
104 |
- } |
|
109 |
+ }, |
|
105 | 110 |
}, |
106 | 111 |
}); |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?