@kne/fastify-app-manager 0.1.41 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/services/menu.js +3 -2
- package/libs/utils/menuManifest.js +21 -1
- package/package.json +1 -1
package/libs/services/menu.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fp = require('fastify-plugin');
|
|
2
2
|
const { isLinked, linkedBaseUrl, linkedApiBaseUrl, KIND_LINKED, KIND_MANAGED } = require('../utils/appKind');
|
|
3
3
|
const { isServed, SERVED_STATUSES } = require('../utils/appAvailability');
|
|
4
|
-
const { normalizeMenuManifest, flattenLeafMenus } = require('../utils/menuManifest');
|
|
4
|
+
const { normalizeMenuManifest, flattenLeafMenus, proxyMenuIcons } = require('../utils/menuManifest');
|
|
5
5
|
const { fetchRemoteModuleConfig } = require('../utils/remoteModuleConfig');
|
|
6
6
|
const { hasLabels, parseLabelI18n, mergeLabelI18n, appDefaultLabels } = require('../utils/labelI18n');
|
|
7
7
|
|
|
@@ -136,7 +136,8 @@ module.exports = fp(async (fastify, options) => {
|
|
|
136
136
|
baseUrl: base,
|
|
137
137
|
// 托管应用取当前部署版本;关联应用没有部署记录,取清单声明的 remote.version
|
|
138
138
|
version: linked ? manifest.remote?.version || null : await currentVersionOf(app),
|
|
139
|
-
|
|
139
|
+
// 关联应用的菜单图标改走网关(同源),见 proxyMenuIcons
|
|
140
|
+
menus: linked && Array.isArray(manifest.menus) ? proxyMenuIcons(manifest.menus, mountPrefix(app.name)) : manifest.menus
|
|
140
141
|
};
|
|
141
142
|
// 应用名称多语言:租户配置 > 应用中心配置 > 子应用 manifest 声明
|
|
142
143
|
const labels = mergeLabelI18n(manifest.labelI18n, app.labelI18n, tenantLabelI18n);
|
|
@@ -180,10 +180,30 @@ const flattenLeafMenus = menus => {
|
|
|
180
180
|
return output;
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
* 关联应用(linked)的菜单图标多为相对路径(如 menu-icons/workspace.svg),宿主前端会按应用 baseUrl 解析,
|
|
185
|
+
* 跨域取图会被 CORS 拦截。改写成网关路径 `${prefix}/${icon}`(即 /app/{name}/...),同源访问,由网关转发到子应用。
|
|
186
|
+
* 绝对地址(http(s)、data:)、以 / 开头的路径与不含目录的值(如文件 id)保持不变。
|
|
187
|
+
*/
|
|
188
|
+
const isRelativeIconPath = icon => typeof icon === 'string' && icon.includes('/') && !/^([a-z][a-z0-9+.-]*:|\/)/i.test(icon);
|
|
189
|
+
|
|
190
|
+
const proxyMenuIcons = (menus, prefix) =>
|
|
191
|
+
(Array.isArray(menus) ? menus : []).map(menu => {
|
|
192
|
+
const next = Object.assign({}, menu);
|
|
193
|
+
if (isRelativeIconPath(menu.icon)) {
|
|
194
|
+
next.icon = `${prefix}/${menu.icon}`;
|
|
195
|
+
}
|
|
196
|
+
if (Array.isArray(menu.children)) {
|
|
197
|
+
next.children = proxyMenuIcons(menu.children, prefix);
|
|
198
|
+
}
|
|
199
|
+
return next;
|
|
200
|
+
});
|
|
201
|
+
|
|
183
202
|
module.exports = {
|
|
184
203
|
MANIFEST_SCHEMA_VERSION,
|
|
185
204
|
INTEGRATIONS,
|
|
186
205
|
DEFAULT_PRESET,
|
|
187
206
|
normalizeMenuManifest,
|
|
188
|
-
flattenLeafMenus
|
|
207
|
+
flattenLeafMenus,
|
|
208
|
+
proxyMenuIcons
|
|
189
209
|
};
|